fix: 修复ws断开时后端无法正常关闭

This commit is contained in:
DLmaster361
2025-08-27 18:35:50 +08:00
parent af402330b2
commit bce9777eae
3 changed files with 38 additions and 6 deletions

View File

@@ -23,6 +23,7 @@
import re
import shutil
import asyncio
import uvicorn
import sqlite3
import calendar
import requests
@@ -584,6 +585,7 @@ class AppConfig(GlobalConfig):
self.config_path.mkdir(parents=True, exist_ok=True)
self.history_path.mkdir(parents=True, exist_ok=True)
self.server: Optional[uvicorn.Server] = None
self.websocket: Optional[WebSocket] = None
self.silence_dict: Dict[Path, datetime] = {}
self.if_ignore_silence: List[uuid.UUID] = []

View File

@@ -221,10 +221,10 @@ class _SystemHandler:
["rundll32.exe", "powrprof.dll,SetSuspendState", "0,1,0"]
)
elif mode == "KillSelf":
elif mode == "KillSelf" and Config.server is not None:
logger.info("执行退出主程序操作")
sys.exit(0)
Config.server.should_exit = True
elif sys.platform.startswith("linux"):
@@ -247,10 +247,10 @@ class _SystemHandler:
logger.info("执行睡眠操作")
subprocess.run(["systemctl", "suspend"])
elif mode == "KillSelf":
elif mode == "KillSelf" and Config.server is not None:
logger.info("执行退出主程序操作")
sys.exit(0)
Config.server.should_exit = True
async def kill_emulator_processes(self):
"""这里暂时仅支持 MuMu 模拟器"""