Gates: a subscription refresh that changes the selected server keeps the connection, network change, auto-switch, smart switch, rotation and the post-core-update reconnect. Manual actions are never gated. Owner request 2026-11-27 (a WoW session dropped every hour). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
97 lines
4.4 KiB
Python
97 lines
4.4 KiB
Python
from __future__ import annotations
|
||
|
||
from typing import TYPE_CHECKING
|
||
|
||
from ..engines.xray import XrayCoreUpdateResult, XrayCoreUpdateWorker
|
||
from .worker_keeper import start_kept
|
||
|
||
if TYPE_CHECKING:
|
||
from .controller import AppController
|
||
|
||
|
||
def run_xray_core_update(controller: AppController, apply_update: bool, silent: bool = False) -> None:
|
||
if controller._xray_update_worker and controller._xray_update_worker.isRunning():
|
||
if not silent:
|
||
controller.status.emit("info", "Обновление Xray уже выполняется")
|
||
return
|
||
|
||
if silent and apply_update and controller.connected:
|
||
controller._log("[core-update] silent auto-update skipped while connected")
|
||
return
|
||
|
||
if apply_update and controller.connected:
|
||
# Остановка перед заменой xray.exe — шаг координатора переходов, не
|
||
# синхронный disconnect_current() в GUI-потоке; воркер обновления
|
||
# стартует, когда подключение действительно остановлено.
|
||
def after_stop(stopped: bool) -> None:
|
||
if not stopped:
|
||
controller._reconnect_after_xray_update = False
|
||
if silent:
|
||
controller._log("[core-update] update cancelled: failed to stop active connection")
|
||
else:
|
||
controller.status.emit("error", "Не удалось остановить активное подключение перед обновлением Xray")
|
||
return
|
||
controller._reconnect_after_xray_update = True
|
||
_start_update_worker(controller, apply_update, silent)
|
||
|
||
if not controller._run_coordinated_stop("core update", after_stop):
|
||
message = "Дождитесь завершения текущего переключения и повторите обновление Xray"
|
||
if silent:
|
||
controller._log(f"[core-update] {message}")
|
||
else:
|
||
controller.status.emit("warning", message)
|
||
return
|
||
|
||
controller._reconnect_after_xray_update = False
|
||
_start_update_worker(controller, apply_update, silent)
|
||
|
||
|
||
def _start_update_worker(controller: AppController, apply_update: bool, silent: bool) -> None:
|
||
controller._xray_update_silent = silent
|
||
controller._xray_update_worker = XrayCoreUpdateWorker(
|
||
controller.state.settings.xray_path,
|
||
controller.state.settings.xray_release_channel,
|
||
controller.state.settings.xray_update_feed_url,
|
||
apply_update=apply_update,
|
||
)
|
||
controller._xray_update_worker.done.connect(controller._on_xray_update_worker_done)
|
||
start_kept(controller._background_workers, controller._xray_update_worker)
|
||
|
||
if not silent:
|
||
message = "Обновление Xray..." if apply_update else "Проверка обновлений Xray..."
|
||
controller.status.emit("info", message)
|
||
|
||
|
||
def on_xray_update_worker_done(controller: AppController, result: XrayCoreUpdateResult) -> None:
|
||
controller._xray_update_worker = None
|
||
controller.xray_update_result.emit(result)
|
||
|
||
if result.status == "error":
|
||
if not controller._xray_update_silent:
|
||
controller.status.emit("error", result.message)
|
||
else:
|
||
controller._log(f"[core-update] error: {result.message}")
|
||
elif result.status == "updated":
|
||
if not controller._xray_update_silent:
|
||
controller.status.emit("success", result.message)
|
||
controller._log(f"[core-update] {result.message}")
|
||
elif result.status == "available":
|
||
if not controller._xray_update_silent:
|
||
controller.status.emit("warning", result.message)
|
||
else:
|
||
controller._log(f"[core-update] {result.message}")
|
||
elif result.status == "up_to_date":
|
||
if not controller._xray_update_silent:
|
||
controller.status.emit("info", result.message)
|
||
else:
|
||
controller._log(f"[core-update] {result.message}")
|
||
|
||
if controller._reconnect_after_xray_update:
|
||
controller._reconnect_after_xray_update = False
|
||
if getattr(controller.state.settings, "auto_reconnect_enabled", True):
|
||
controller._desired_connected = True
|
||
controller._request_transition("core update reconnect")
|
||
else:
|
||
controller._log("[core-update] the core was updated; the connection is kept until you reconnect")
|
||
|
||
controller._xray_update_silent = False
|