feat: 添加电源接口,适配小功能函数

This commit is contained in:
DLmaster361
2025-08-17 10:53:00 +08:00
parent 1fdac22bea
commit 8e2c6bb642
7 changed files with 94 additions and 84 deletions

View File

@@ -659,7 +659,6 @@ class AppConfig(GlobalConfig):
self.history_path.mkdir(parents=True, exist_ok=True)
self.silence_dict: Dict[Path, datetime] = {}
self.power_sign = "NoAction"
self.if_ignore_silence: List[uuid.UUID] = []
self.temp_task: List[asyncio.Task] = []

View File

@@ -22,6 +22,7 @@ import asyncio
import keyboard
from datetime import datetime
from app.services import System
from app.utils import get_logger
from .config import Config
@@ -31,9 +32,6 @@ logger = get_logger("主业务定时器")
class _MainTimer:
def __init__(self):
super().__init__()
async def second_task(self):
"""每秒定期任务"""
logger.info("每秒定期任务启动")
@@ -41,7 +39,6 @@ class _MainTimer:
while True:
await self.set_silence()
await self.check_power()
await asyncio.sleep(1)
@@ -54,68 +51,36 @@ class _MainTimer:
and Config.get("Function", "BossKey") != ""
):
pass
windows = await System.get_window_info()
# windows = System.get_window_info()
emulator_windows = []
for window in windows:
for emulator_path, endtime in Config.silence_dict.items():
if (
datetime.now() < endtime
and str(emulator_path) in window
and window[0] != "新通知" # 此处排除雷电名为新通知的窗口
):
emulator_windows.append(window)
# emulator_windows = []
# for window in windows:
# for emulator_path, endtime in Config.silence_dict.items():
# if (
# datetime.now() < endtime
# and str(emulator_path) in window
# and window[0] != "新通知" # 此处排除雷电名为新通知的窗口
# ):
# emulator_windows.append(window)
if emulator_windows:
# if emulator_windows:
# logger.info(
# f"检测到模拟器窗口:{emulator_windows}", module="主业务定时器"
# )
# try:
# keyboard.press_and_release(
# "+".join(
# _.strip().lower()
# for _ in Config.get(Config.function_BossKey).split("+")
# )
# )
# logger.info(
# f"模拟按键:{Config.get(Config.function_BossKey)}",
# module="主业务定时器",
# )
# except Exception as e:
# logger.exception(f"模拟按键时出错:{e}", module="主业务定时器")
async def check_power(self):
"""检查电源操作"""
# if Config.power_sign != "NoAction" and not Config.running_list:
# logger.info(f"触发电源操作:{Config.power_sign}", module="主业务定时器")
# from app.ui import ProgressRingMessageBox
# mode_book = {
# "KillSelf": "退出软件",
# "Sleep": "睡眠",
# "Hibernate": "休眠",
# "Shutdown": "关机",
# "ShutdownForce": "关机(强制)",
# }
# choice = ProgressRingMessageBox(
# Config.main_window, f"{mode_book[Config.power_sign]}倒计时"
# )
# if choice.exec():
# logger.info(
# f"确认执行电源操作:{Config.power_sign}", module="主业务定时器"
# )
# System.set_power(Config.power_sign)
# Config.set_power_sign("NoAction")
# else:
# logger.info(f"取消电源操作:{Config.power_sign}", module="主业务定时器")
# Config.set_power_sign("NoAction")
logger.info(
f"检测到模拟器窗口:{emulator_windows}", module="主业务定时器"
)
try:
keyboard.press_and_release(
"+".join(
_.strip().lower()
for _ in Config.get("Function", "BossKey").split("+")
)
)
logger.info(
f"模拟按键:{Config.get('Function', 'BossKey')}",
module="主业务定时器",
)
except Exception as e:
logger.exception(f"模拟按键时出错:{e}", module="主业务定时器")
MainTimer = _MainTimer()