Skip to content

Commit

Permalink
v3.1.0 - 在有任务正在下载时阻止系统休眠,但允许屏幕关闭 - #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Jan 18, 2020
1 parent 41fb436 commit ed9e361
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aria-ng-gui",
"version": "3.0.0",
"version": "3.1.0",
"private": true,
"description": "AriaNg GUI",
"main": "app.js",
Expand Down
1 change: 1 addition & 0 deletions app/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const plugins = [
require("./save-local-config"),
require("./notification"),
require("./trackers"),
require("./power-save-blocker"),
]

module.exports = plugins
62 changes: 62 additions & 0 deletions app/plugins/power-save-blocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*!
* AriaNg GUI
*
* Copyright (c) 2018-2020 Xmader
* Released under the MIT license
*
* Source Code: https://github.com/Xmader/aria-ng-gui
*
* power-save-blocker.js - 在有任务正在下载时阻止系统休眠,但允许屏幕关闭
* https://github.com/Xmader/aria-ng-gui/issues/34
*/

// @ts-check

const { powerSaveBlocker } = require("electron").remote

class PowerSaveBlocker {

/** @type {number} */
id = null

start() {
if (this.id !== null) {
return
}

// 阻止系统休眠,但允许屏幕关闭
this.id = powerSaveBlocker.start("prevent-app-suspension")

console.log("powerSaveBlocker started")
}

stop() {
if (this.id !== null && powerSaveBlocker.isStarted(this.id)) {
powerSaveBlocker.stop(this.id)
this.id = null
console.log("powerSaveBlocker stopped")
}
}

}

const blocker = new PowerSaveBlocker()

/**
* @typedef {import("./index").Plugin} Plugin
* @type {Plugin}
*/
module.exports = {
activate(context) {

context.addListener("downloading", (tasks) => {
const isDownloading = tasks.length > 0
if (isDownloading) {
blocker.start()
} else {
blocker.stop()
}
})

}
}

0 comments on commit ed9e361

Please sign in to comment.