mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-08-10 00:03:19 +03:00
fix (macOS): crash fix on settings open
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import faulthandler
|
import faulthandler
|
||||||
|
import queue
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -118,6 +119,7 @@ _ns_app: Optional[Any] = None
|
|||||||
_config: dict = {}
|
_config: dict = {}
|
||||||
_exiting = False
|
_exiting = False
|
||||||
_crash_log: Optional[Any] = None
|
_crash_log: Optional[Any] = None
|
||||||
|
_ui_queue: queue.Queue = queue.Queue()
|
||||||
|
|
||||||
|
|
||||||
def _activate_app() -> None:
|
def _activate_app() -> None:
|
||||||
@@ -151,13 +153,32 @@ def _dispatch(callback: Callable[[], None], delay_ms: int = 0) -> None:
|
|||||||
except Exception as dialog_exc:
|
except Exception as dialog_exc:
|
||||||
log.error("Failed to show UI error: %s", repr(dialog_exc))
|
log.error("Failed to show UI error: %s", repr(dialog_exc))
|
||||||
|
|
||||||
|
_ui_queue.put((time.monotonic() + delay_ms / 1000.0, invoke))
|
||||||
|
|
||||||
|
|
||||||
|
def _pump_ui_queue() -> None:
|
||||||
|
root = _ctk_root
|
||||||
|
if root is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
now = time.monotonic()
|
||||||
|
deferred = []
|
||||||
|
for _ in range(32):
|
||||||
try:
|
try:
|
||||||
if delay_ms > 0:
|
due_at, callback = _ui_queue.get_nowait()
|
||||||
_ctk_root.after(delay_ms, invoke)
|
except queue.Empty:
|
||||||
|
break
|
||||||
|
if due_at <= now:
|
||||||
|
callback()
|
||||||
else:
|
else:
|
||||||
_ctk_root.after_idle(invoke)
|
deferred.append((due_at, callback))
|
||||||
except Exception as exc:
|
for item in deferred:
|
||||||
log.warning("Failed to dispatch UI callback: %s", repr(exc))
|
_ui_queue.put(item)
|
||||||
|
|
||||||
|
try:
|
||||||
|
root.after(20, _pump_ui_queue)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _messagebox(kind: str, text: str, title: str) -> Any:
|
def _messagebox(kind: str, text: str, title: str) -> Any:
|
||||||
@@ -510,6 +531,7 @@ def _initialize_gui() -> bool:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.warning("Failed to make CTk root transparent: %s", repr(exc))
|
log.warning("Failed to make CTk root transparent: %s", repr(exc))
|
||||||
_ctk_root.withdraw()
|
_ctk_root.withdraw()
|
||||||
|
_ctk_root.after(20, _pump_ui_queue)
|
||||||
_ns_app = NSApplication.sharedApplication()
|
_ns_app = NSApplication.sharedApplication()
|
||||||
if NSApplicationActivationPolicyAccessory is not None:
|
if NSApplicationActivationPolicyAccessory is not None:
|
||||||
_ns_app.setActivationPolicy_(NSApplicationActivationPolicyAccessory)
|
_ns_app.setActivationPolicy_(NSApplicationActivationPolicyAccessory)
|
||||||
|
|||||||
Reference in New Issue
Block a user