Merge pull request #22 from ClozyA:auto_shutdown
feat(core): 添加运行完成后自动关机功能
This commit is contained in:
@@ -542,6 +542,8 @@ class GlobalConfig(QConfig):
|
|||||||
function_IfSilence = ConfigItem("Function", "IfSilence", False, BoolValidator())
|
function_IfSilence = ConfigItem("Function", "IfSilence", False, BoolValidator())
|
||||||
function_BossKey = ConfigItem("Function", "BossKey", "")
|
function_BossKey = ConfigItem("Function", "BossKey", "")
|
||||||
|
|
||||||
|
function_AutoShutdown = ConfigItem("Function", "AutoShutdown", False, BoolValidator())
|
||||||
|
|
||||||
start_IfSelfStart = ConfigItem("Start", "IfSelfStart", False, BoolValidator())
|
start_IfSelfStart = ConfigItem("Start", "IfSelfStart", False, BoolValidator())
|
||||||
start_IfRunDirectly = ConfigItem("Start", "IfRunDirectly", False, BoolValidator())
|
start_IfRunDirectly = ConfigItem("Start", "IfRunDirectly", False, BoolValidator())
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ MAA功能组件
|
|||||||
v4.2
|
v4.2
|
||||||
作者:DLmaster_361
|
作者:DLmaster_361
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from PySide6.QtCore import QObject, Signal, QEventLoop
|
from PySide6.QtCore import QObject, Signal, QEventLoop
|
||||||
@@ -538,6 +539,13 @@ class MaaManager(QObject):
|
|||||||
f"{self.mode[:4]}任务报告",
|
f"{self.mode[:4]}任务报告",
|
||||||
f"{end_log}AUTO_MAA 敬上",
|
f"{end_log}AUTO_MAA 敬上",
|
||||||
)
|
)
|
||||||
|
if Config.global_config.function_AutoShutdown:
|
||||||
|
logger.info("任务完成,系统将在 60 秒后自动关机...")
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
subprocess.run("shutdown /s /t 60", shell=True) # Windows
|
||||||
|
else:
|
||||||
|
# 看到 Issues 里有兼容 Linux 的计划,加上 Linux 的
|
||||||
|
subprocess.run("shutdown -h +1", shell=True) # Linux/macOS
|
||||||
|
|
||||||
self.accomplish.emit({"Time": begin_time, "History": end_log})
|
self.accomplish.emit({"Time": begin_time, "History": end_log})
|
||||||
|
|
||||||
|
|||||||
@@ -399,11 +399,20 @@ class FunctionSettingCard(HeaderCardWidget):
|
|||||||
content="仅阻止电脑自动休眠,不会影响屏幕是否熄灭",
|
content="仅阻止电脑自动休眠,不会影响屏幕是否熄灭",
|
||||||
configItem=Config.global_config.function_IfAllowSleep,
|
configItem=Config.global_config.function_IfAllowSleep,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.card_AutoShutdown = SwitchSettingCard(
|
||||||
|
icon=FluentIcon.POWER_BUTTON,
|
||||||
|
title="运行完成后自动关机",
|
||||||
|
content="启用后,任务完成后将自动关机",
|
||||||
|
configItem=Config.global_config.function_AutoShutdown,
|
||||||
|
)
|
||||||
|
|
||||||
self.card_IfSilence = self.SilenceSettingCard(self)
|
self.card_IfSilence = self.SilenceSettingCard(self)
|
||||||
|
|
||||||
Layout = QVBoxLayout()
|
Layout = QVBoxLayout()
|
||||||
Layout.addWidget(self.card_IfAllowSleep)
|
Layout.addWidget(self.card_IfAllowSleep)
|
||||||
Layout.addWidget(self.card_IfSilence)
|
Layout.addWidget(self.card_IfSilence)
|
||||||
|
Layout.addWidget(self.card_AutoShutdown)
|
||||||
self.viewLayout.addLayout(Layout)
|
self.viewLayout.addLayout(Layout)
|
||||||
|
|
||||||
class SilenceSettingCard(ExpandGroupSettingCard):
|
class SilenceSettingCard(ExpandGroupSettingCard):
|
||||||
@@ -753,3 +762,7 @@ def version_text(version_numb: list) -> str:
|
|||||||
f"v{'.'.join(str(_) for _ in version_numb[0:3])}-beta.{version_numb[3]}"
|
f"v{'.'.join(str(_) for _ in version_numb[0:3])}-beta.{version_numb[3]}"
|
||||||
)
|
)
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
def toggle_auto_shutdown(self, checked: bool) -> None:
|
||||||
|
"""启用或禁用自动关机"""
|
||||||
|
Config.global_config.function_AutoShutdown = checked
|
||||||
|
|||||||
Reference in New Issue
Block a user