Răsfoiți Sursa

!2 close frpc at last time

pcacc 4 zile în urmă
părinte
comite
7003cbb360
2 a modificat fișierele cu 17 adăugiri și 1 ștergeri
  1. 16 1
      app_dongri.py
  2. 1 0
      dongri_task.py

+ 16 - 1
app_dongri.py

@@ -36,6 +36,17 @@ class GlobalState:
     g_isRestart = True
     last_change_time = time.time()
     g_firstRunBear = True
+    frp_process = None
+
+def startup_frpc():
+    GlobalState.frp_process = subprocess.Popen(["tool/frpc.exe", "-c", "tool/frpc-desktop.toml"])
+
+def terminate_frpc():
+    if GlobalState.frp_process is not None:
+        proc = GlobalState.frp_process
+        proc.terminate()  # 优雅终止
+        if proc.poll() is None:  # 检查是否仍在运行
+            proc.kill()  # 强制终止
 
 @app.after_request
 def add_no_cache_header(response):
@@ -175,6 +186,8 @@ def handle_reset_script():
     print(f"当前脚本路径: {script}")
     print(f"重置参数: {[python, script, *new_args, '']}")
 
+    terminate_frpc()
+
     try:
         os.execv(python, [python, script, *new_args, ''])
     except Exception as e:
@@ -194,6 +207,8 @@ def handle_restart_game():
     print(f"当前脚本路径: {script}")
     print(f"重启参数: {[python, script, *new_args, '--reset']}")
 
+    terminate_frpc()
+
     try:
         os.execv(python, [python, script, *new_args, '--reset'])
     except Exception as e:
@@ -674,7 +689,7 @@ def monitor_game_runtime():
 
 if __name__ == '__main__':
     init()
-    process = subprocess.Popen(["tool/frpc.exe", "-c", "tool/frpc-desktop.toml"])
+    startup_frpc()
     print("FRPC已启动,主程序继续运行...")
     if '--reset' in sys.argv:
         time.sleep(2)

+ 1 - 0
dongri_task.py

@@ -114,6 +114,7 @@ def init():
             acceptTask.start()
             _imported = True
 
+
 class basic_operate:
     @staticmethod
     def do_back():