fix: settings dialog now runs in its own thread, increasing responsiveness.

This commit is contained in:
serversdwn
2026-03-17 13:36:35 -04:00
parent 9cfdebe553
commit 814b6f915e

View File

@@ -246,15 +246,13 @@ class WatcherTray:
# --- Menu item callbacks --- # --- Menu item callbacks ---
def _open_settings(self, icon, item): def _open_settings(self, icon, item):
"""Open the settings dialog. On save, restart watcher thread.""" """Open the settings dialog in its own thread so the tray stays responsive."""
def _run():
from settings_dialog import show_dialog from settings_dialog import show_dialog
saved = show_dialog(CONFIG_PATH, wizard=False) saved = show_dialog(CONFIG_PATH, wizard=False)
if saved: if saved:
self._restart_watcher() self._restart_watcher()
# Rebuild menu so status label refreshes threading.Thread(target=_run, daemon=True, name="settings-dialog").start()
if self._icon is not None:
with self._menu_lock:
self._icon.menu = self._build_menu()
def _open_logs(self, icon, item): def _open_logs(self, icon, item):
log_dir = self.state.get("log_dir") log_dir = self.state.get("log_dir")
@@ -312,17 +310,12 @@ class WatcherTray:
return pystray.Menu(*items) return pystray.Menu(*items)
def _build_menu(self): def _build_menu(self):
# Capture current text/submenu at build time; pystray will call # Use a callable for the status item so pystray re-evaluates it
# callables each render, but static strings are fine for infrequent # every time the menu is opened — keeps it in sync with the tooltip.
# menu rebuilds. We use callables for the dynamic items so that the
# text shown on hover/open is current.
status_text = self._status_text()
units_submenu = self._build_units_submenu()
return pystray.Menu( return pystray.Menu(
pystray.MenuItem(status_text, None, enabled=False), pystray.MenuItem(lambda item: self._status_text(), None, enabled=False),
pystray.Menu.SEPARATOR, pystray.Menu.SEPARATOR,
pystray.MenuItem("Units", units_submenu), pystray.MenuItem("Units", lambda item: self._build_units_submenu()),
pystray.Menu.SEPARATOR, pystray.Menu.SEPARATOR,
pystray.MenuItem("Settings...", self._open_settings), pystray.MenuItem("Settings...", self._open_settings),
pystray.MenuItem("Open Log Folder", self._open_logs), pystray.MenuItem("Open Log Folder", self._open_logs),