diff --git a/app/api/core.py b/app/api/core.py index db3d3c2..b0c6f30 100644 --- a/app/api/core.py +++ b/app/api/core.py @@ -79,3 +79,16 @@ async def connect_websocket(websocket: WebSocket): Config.websocket = None await System.set_power("KillSelf") + + +@router.post("/close") +async def close(): + """关闭后端程序""" + + try: + await System.set_power("KillSelf") + except Exception as e: + return OutBase( + code=500, status="error", message=f"{type(e).__name__}: {str(e)}" + ) + return OutBase() diff --git a/app/core/timer.py b/app/core/timer.py index a5be594..c803a56 100644 --- a/app/core/timer.py +++ b/app/core/timer.py @@ -111,8 +111,6 @@ class _MainTimer: async def set_silence(self): """静默模式通过模拟老板键来隐藏模拟器窗口""" - logger.debug("检查静默模式") - if ( len(Config.if_ignore_silence) > 0 and Config.get("Function", "IfSilence") @@ -145,7 +143,5 @@ class _MainTimer: except Exception as e: logger.exception(f"模拟按键时出错: {e}") - logger.debug("静默模式检查完毕") - MainTimer = _MainTimer() diff --git a/main.py b/main.py index 9a2c3da..c630b0e 100644 --- a/main.py +++ b/main.py @@ -77,6 +77,7 @@ def main(): from app.core import Config, MainTimer, TaskManager from app.services import System + from app.models.schema import WebSocketMessage await Config.init_config() await Config.get_stage(if_start=True) @@ -101,6 +102,12 @@ def main(): await Matomo.close() + await Config.send_json( + WebSocketMessage( + id="Main", type="Signal", data={"Close": "后端已安全关闭"} + ).model_dump() + ) + logger.info("AUTO-MAS 后端程序关闭") from fastapi.middleware.cors import CORSMiddleware