|
@@ -36,6 +36,17 @@ class GlobalState:
|
|
g_isRestart = True
|
|
g_isRestart = True
|
|
last_change_time = time.time()
|
|
last_change_time = time.time()
|
|
g_firstRunBear = True
|
|
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
|
|
@app.after_request
|
|
def add_no_cache_header(response):
|
|
def add_no_cache_header(response):
|
|
@@ -175,6 +186,8 @@ def handle_reset_script():
|
|
print(f"当前脚本路径: {script}")
|
|
print(f"当前脚本路径: {script}")
|
|
print(f"重置参数: {[python, script, *new_args, '']}")
|
|
print(f"重置参数: {[python, script, *new_args, '']}")
|
|
|
|
|
|
|
|
+ terminate_frpc()
|
|
|
|
+
|
|
try:
|
|
try:
|
|
os.execv(python, [python, script, *new_args, ''])
|
|
os.execv(python, [python, script, *new_args, ''])
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -194,6 +207,8 @@ def handle_restart_game():
|
|
print(f"当前脚本路径: {script}")
|
|
print(f"当前脚本路径: {script}")
|
|
print(f"重启参数: {[python, script, *new_args, '--reset']}")
|
|
print(f"重启参数: {[python, script, *new_args, '--reset']}")
|
|
|
|
|
|
|
|
+ terminate_frpc()
|
|
|
|
+
|
|
try:
|
|
try:
|
|
os.execv(python, [python, script, *new_args, '--reset'])
|
|
os.execv(python, [python, script, *new_args, '--reset'])
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -674,7 +689,7 @@ def monitor_game_runtime():
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
init()
|
|
init()
|
|
- process = subprocess.Popen(["tool/frpc.exe", "-c", "tool/frpc-desktop.toml"])
|
|
|
|
|
|
+ startup_frpc()
|
|
print("FRPC已启动,主程序继续运行...")
|
|
print("FRPC已启动,主程序继续运行...")
|
|
if '--reset' in sys.argv:
|
|
if '--reset' in sys.argv:
|
|
time.sleep(2)
|
|
time.sleep(2)
|