Skip to content

The only downloader you need. 下载器的集大成者。

feat(Plan): 计划任务支持下载完成后睡眠

XiaoYouChRda76eb543b75
diff --git a/CONTEXT.md b/CONTEXT.md
index 51f3f7e6..528e3880 100644
--- a/CONTEXT.md
+++ b/CONTEXT.md
@@ -141,7 +141,7 @@ Process-level event bus with exactly four signals: `activationRequested`,
business signals — those live on Task Service and Speed Meter.
**Plan**:
-A "do X after all tasks complete" intent: shutdown, restart, or open file.
+A "do X after all tasks complete" intent: shutdown, restart, sleep, or open file.
### Verb vocabulary
diff --git a/app/assets/i18n/gd3.en_US.ts b/app/assets/i18n/gd3.en_US.ts
index 30984149..72a0f7d3 100644
--- a/app/assets/i18n/gd3.en_US.ts
+++ b/app/assets/i18n/gd3.en_US.ts
@@ -2692,6 +2692,11 @@ Only allow this request if you have requested "Auto Pair" from the ext
</message>
<message>
<location filename="../../view/dialogs/plan_task.py" line="20"/>
+ <source>睡眠</source>
+ <translation>Sleep</translation>
+ </message>
+ <message>
+ <location filename="../../view/dialogs/plan_task.py" line="21"/>
<source>打开文件</source>
<translation>Open File</translation>
</message>
diff --git a/app/platform/desktop.py b/app/platform/desktop.py
index 1703e954..2e12bffc 100644
--- a/app/platform/desktop.py
+++ b/app/platform/desktop.py
@@ -119,6 +119,17 @@ def restart() -> None:
Popen(["shutdown", "-r", "now"])
+def sleep() -> None:
+ from subprocess import Popen
+ match sys.platform:
+ case "win32":
+ Popen(["rundll32.exe", "powrprof.dll,SetSuspendState", "0", "1", "0"])
+ case "darwin":
+ Popen(["pmset", "sleepnow"])
+ case _:
+ Popen(["systemctl", "suspend"])
+
+
def openChromiumUrl(url: str) -> bool:
import shutil
import subprocess
diff --git a/app/services/plan.py b/app/services/plan.py
index 010656ef..09439a34 100644
--- a/app/services/plan.py
+++ b/app/services/plan.py
@@ -4,7 +4,8 @@ from enum import IntEnum
class PlanAction(IntEnum):
SHUTDOWN = 0
RESTART = 1
- OPEN_FILE = 2
+ SLEEP = 2
+ OPEN_FILE = 3
class Plan:
@@ -35,7 +36,7 @@ class Plan:
if any(t.status != TaskStatus.COMPLETED for t in taskService.tasks):
return
- from app.platform.desktop import openFile, restart, shutdown
+ from app.platform.desktop import openFile, restart, shutdown, sleep
action, filePath = self.action, self.filePath
self.clear()
@@ -45,6 +46,8 @@ class Plan:
openFile(filePath)
elif action == PlanAction.RESTART:
restart()
+ elif action == PlanAction.SLEEP:
+ sleep()
else:
shutdown()
diff --git a/app/view/dialogs/plan_task.py b/app/view/dialogs/plan_task.py
index ff549920..a6e101c8 100644
--- a/app/view/dialogs/plan_task.py
+++ b/app/view/dialogs/plan_task.py
@@ -17,6 +17,7 @@ class PlanTaskDialog(MessageBoxBase):
self.radioGroup = QButtonGroup(self)
self.shutdownButton = RadioButton(self.tr("关机"), self)
self.restartButton = RadioButton(self.tr("重启"), self)
+ self.sleepButton = RadioButton(self.tr("睡眠"), self)
self.openFileButton = RadioButton(self.tr("打开文件"), self)
self.pathContainer = QWidget(self)
self.pathLayout = QHBoxLayout(self.pathContainer)
@@ -34,6 +35,7 @@ class PlanTaskDialog(MessageBoxBase):
self.radioGroup.addButton(self.shutdownButton)
self.radioGroup.addButton(self.restartButton)
+ self.radioGroup.addButton(self.sleepButton)
self.radioGroup.addButton(self.openFileButton)
self.radioGroup.setExclusive(True)
self.shutdownButton.setChecked(True)
@@ -55,6 +57,7 @@ class PlanTaskDialog(MessageBoxBase):
optionsLayout.setSpacing(10)
optionsLayout.addWidget(self.shutdownButton)
optionsLayout.addWidget(self.restartButton)
+ optionsLayout.addWidget(self.sleepButton)
optionsLayout.addWidget(self.openFileButton)
self.viewLayout.addWidget(self.titleLabel)
@@ -80,6 +83,8 @@ class PlanTaskDialog(MessageBoxBase):
def selectedAction(self) -> int:
if self.radioGroup.checkedButton() is self.restartButton:
return PlanAction.RESTART
+ if self.radioGroup.checkedButton() is self.sleepButton:
+ return PlanAction.SLEEP
if self.radioGroup.checkedButton() is self.openFileButton:
return PlanAction.OPEN_FILE
return PlanAction.SHUTDOWN