From ed9e36185cf7f410ee0e14684e1c119b6e005862 Mon Sep 17 00:00:00 2001 From: Xmader Date: Sat, 18 Jan 2020 18:01:56 -0500 Subject: [PATCH] =?UTF-8?q?v3.1.0=20-=20=E5=9C=A8=E6=9C=89=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=AD=A3=E5=9C=A8=E4=B8=8B=E8=BD=BD=E6=97=B6=E9=98=BB?= =?UTF-8?q?=E6=AD=A2=E7=B3=BB=E7=BB=9F=E4=BC=91=E7=9C=A0=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=B1=8F=E5=B9=95=E5=85=B3=E9=97=AD=20-=20#3?= =?UTF-8?q?4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/package.json | 2 +- app/plugins/index.js | 1 + app/plugins/power-save-blocker.js | 62 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 app/plugins/power-save-blocker.js diff --git a/app/package.json b/app/package.json index c0c3e40..b484511 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "aria-ng-gui", - "version": "3.0.0", + "version": "3.1.0", "private": true, "description": "AriaNg GUI", "main": "app.js", diff --git a/app/plugins/index.js b/app/plugins/index.js index fa55052..eb9b654 100644 --- a/app/plugins/index.js +++ b/app/plugins/index.js @@ -20,6 +20,7 @@ const plugins = [ require("./save-local-config"), require("./notification"), require("./trackers"), + require("./power-save-blocker"), ] module.exports = plugins diff --git a/app/plugins/power-save-blocker.js b/app/plugins/power-save-blocker.js new file mode 100644 index 0000000..ca5623a --- /dev/null +++ b/app/plugins/power-save-blocker.js @@ -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() + } + }) + + } +}