diff --git a/macos.py b/macos.py index 8bc602a..d26ff7d 100644 --- a/macos.py +++ b/macos.py @@ -185,7 +185,7 @@ def _run_proxy_thread() -> None: loop.run_until_complete(_run(stop_event=stop_ev)) except Exception as exc: log.error("Proxy thread crashed: %s", exc) - msg = diagnose_listen_error(exc) + msg, _ = diagnose_listen_error(exc) if msg: _show_error(msg) finally: diff --git a/utils/diagnostics.py b/utils/diagnostics.py index 4301496..76caeba 100644 --- a/utils/diagnostics.py +++ b/utils/diagnostics.py @@ -1,8 +1,9 @@ from __future__ import annotations import errno +import webbrowser -from typing import Optional +from typing import Optional, Tuple, Callable MSG_PORT_BUSY = ( @@ -23,6 +24,7 @@ MSG_PERMISSION = ( MSG_BAD_ADDRESS = ( "Не удалось запустить прокси:\n" "Некорректный или недоступный адрес для прослушивания.\n\n" + "Проверьте решение по открывшейся в браузере ссылке.\n" "Проверьте host и порт в настройках прокси и перезапустите." ) @@ -33,7 +35,7 @@ _WSA_EADDRINUSE = 10048 _WSA_EADDRNOTAVAIL = 10049 -def diagnose_listen_error(exc: BaseException) -> Optional[str]: +def diagnose_listen_error(exc: BaseException) -> Tuple[Optional[str], Optional[Callable]]: """Map a listen-socket bind failure to a user-facing message. Returns None when the exception is not a recognizable bind failure, @@ -46,10 +48,10 @@ def diagnose_listen_error(exc: BaseException) -> Optional[str]: winerror = getattr(exc, "winerror", None) if err == errno.EADDRINUSE or winerror == _WSA_EADDRINUSE: - return MSG_PORT_BUSY + return MSG_PORT_BUSY, None if err == errno.EACCES or winerror == _WSA_EACCES: - return MSG_PERMISSION + return MSG_PERMISSION, None if (winerror in (_WSA_EFAULT, _WSA_EADDRNOTAVAIL) or err in (errno.EADDRNOTAVAIL, errno.EFAULT)): - return MSG_BAD_ADDRESS - return None + return MSG_BAD_ADDRESS, lambda : webbrowser.open("https://github.com/Flowseal/tg-ws-proxy/issues/903#issuecomment-4726752103") + return None, None diff --git a/utils/tray_common.py b/utils/tray_common.py index 2a78f92..9739b81 100644 --- a/utils/tray_common.py +++ b/utils/tray_common.py @@ -228,7 +228,7 @@ _proxy_thread: Optional[threading.Thread] = None _async_stop: Optional[Tuple[asyncio.AbstractEventLoop, asyncio.Event]] = None -def _run_proxy_thread(on_port_busy: Callable[[str], None]) -> None: +def _run_proxy_thread(show_error: Callable[[str], None]) -> None: global _async_stop loop = asyncio.new_event_loop() @@ -240,9 +240,11 @@ def _run_proxy_thread(on_port_busy: Callable[[str], None]) -> None: loop.run_until_complete(_run(stop_event=stop_ev)) except Exception as exc: log.error("Proxy thread crashed: %s", repr(exc)) - msg = diagnose_listen_error(exc) + msg, diagnose_called = diagnose_listen_error(exc) if msg: - on_port_busy(msg) + show_error(msg) + if diagnose_called: + diagnose_called() finally: loop.close() _async_stop = None