macos build recode

This commit is contained in:
Flowseal
2026-08-07 00:00:38 +03:00
parent eb73c1b680
commit e69d101622
+25 -2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
import faulthandler
import subprocess import subprocess
import sys import sys
import threading import threading
@@ -89,6 +90,7 @@ from ui.ctk_tray_ui import (
) )
from ui.i18n import set_language, t from ui.i18n import set_language, t
from utils.tray_common import ( from utils.tray_common import (
APP_DIR,
APP_NAME, APP_NAME,
DEFAULT_CONFIG, DEFAULT_CONFIG,
FIRST_RUN_MARKER, FIRST_RUN_MARKER,
@@ -115,6 +117,7 @@ _settings_window: Optional[Any] = None
_ns_app: Optional[Any] = None _ns_app: Optional[Any] = None
_config: dict = {} _config: dict = {}
_exiting = False _exiting = False
_crash_log: Optional[Any] = None
def _activate_app() -> None: def _activate_app() -> None:
@@ -134,7 +137,7 @@ def _hide_ctk_root() -> None:
log.warning("Failed to hide CTk root: %s", repr(exc)) log.warning("Failed to hide CTk root: %s", repr(exc))
def _dispatch(callback: Callable[[], None]) -> None: def _dispatch(callback: Callable[[], None], delay_ms: int = 0) -> None:
if _ctk_root is None: if _ctk_root is None:
return return
@@ -149,6 +152,9 @@ def _dispatch(callback: Callable[[], None]) -> None:
log.error("Failed to show UI error: %s", repr(dialog_exc)) log.error("Failed to show UI error: %s", repr(dialog_exc))
try: try:
if delay_ms > 0:
_ctk_root.after(delay_ms, invoke)
else:
_ctk_root.after_idle(invoke) _ctk_root.after_idle(invoke)
except Exception as exc: except Exception as exc:
log.warning("Failed to dispatch UI callback: %s", repr(exc)) log.warning("Failed to dispatch UI callback: %s", repr(exc))
@@ -265,7 +271,8 @@ def _on_restart(icon=None, item=None) -> None:
def _on_edit_config(icon=None, item=None) -> None: def _on_edit_config(icon=None, item=None) -> None:
_dispatch(_edit_config_dialog) log.info("Settings requested")
_dispatch(_edit_config_dialog, delay_ms=300)
def _on_open_logs(icon=None, item=None) -> None: def _on_open_logs(icon=None, item=None) -> None:
@@ -310,6 +317,7 @@ def _edit_config_dialog() -> None:
log.warning("Failed to reuse settings window: %s", repr(exc)) log.warning("Failed to reuse settings window: %s", repr(exc))
_settings_window = None _settings_window = None
log.info("Creating settings window")
cfg = dict(_config) cfg = dict(_config)
theme = ctk_theme_for_platform() theme = ctk_theme_for_platform()
width, height = CONFIG_DIALOG_SIZE width, height = CONFIG_DIALOG_SIZE
@@ -322,6 +330,7 @@ def _edit_config_dialog() -> None:
after_create=lambda window: _activate_app(), after_create=lambda window: _activate_app(),
) )
_settings_window = root _settings_window = root
log.info("Settings window created")
frame_pad_x, frame_pad_y = CONFIG_DIALOG_FRAME_PAD frame_pad_x, frame_pad_y = CONFIG_DIALOG_FRAME_PAD
frame = main_content_frame( frame = main_content_frame(
ctk, ctk,
@@ -332,6 +341,7 @@ def _edit_config_dialog() -> None:
) )
scroll, footer = tray_settings_scroll_and_footer(ctk, frame, theme) scroll, footer = tray_settings_scroll_and_footer(ctk, frame, theme)
original_language = _config.get("language", DEFAULT_CONFIG["language"]) original_language = _config.get("language", DEFAULT_CONFIG["language"])
log.info("Building settings form")
widgets = install_tray_config_form( widgets = install_tray_config_form(
ctk, ctk,
scroll, scroll,
@@ -341,6 +351,7 @@ def _edit_config_dialog() -> None:
show_autostart=False, show_autostart=False,
on_language_change=_refresh_tray_menu, on_language_change=_refresh_tray_menu,
) )
log.info("Settings form built")
original_appearance = ctk.get_appearance_mode() original_appearance = ctk.get_appearance_mode()
def restore_ui_locale() -> None: def restore_ui_locale() -> None:
@@ -419,6 +430,7 @@ def _edit_config_dialog() -> None:
on_cancel=cancel, on_cancel=cancel,
) )
_activate_app() _activate_app()
log.info("Settings window ready")
def _show_first_run() -> None: def _show_first_run() -> None:
@@ -504,10 +516,21 @@ def _initialize_gui() -> bool:
return True return True
def _enable_crash_log() -> None:
global _crash_log
try:
ensure_dirs()
_crash_log = open(APP_DIR / "crash.log", "a", encoding="utf-8", buffering=1)
faulthandler.enable(file=_crash_log, all_threads=True)
except OSError as exc:
log.warning("Failed to enable crash log: %s", repr(exc))
def run_tray() -> None: def run_tray() -> None:
global _tray_icon, _config global _tray_icon, _config
_config = load_config() _config = load_config()
bootstrap(_config) bootstrap(_config)
_enable_crash_log()
if not _initialize_gui(): if not _initialize_gui():
log.error("pystray, Pillow, customtkinter or AppKit not installed; running in console mode") log.error("pystray, Pillow, customtkinter or AppKit not installed; running in console mode")