fix: settings dialog now runs in its own thread, increasing responsiveness.
This commit is contained in:
@@ -246,15 +246,13 @@ class WatcherTray:
|
||||
# --- Menu item callbacks ---
|
||||
|
||||
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
|
||||
saved = show_dialog(CONFIG_PATH, wizard=False)
|
||||
if saved:
|
||||
self._restart_watcher()
|
||||
# Rebuild menu so status label refreshes
|
||||
if self._icon is not None:
|
||||
with self._menu_lock:
|
||||
self._icon.menu = self._build_menu()
|
||||
threading.Thread(target=_run, daemon=True, name="settings-dialog").start()
|
||||
|
||||
def _open_logs(self, icon, item):
|
||||
log_dir = self.state.get("log_dir")
|
||||
@@ -312,17 +310,12 @@ class WatcherTray:
|
||||
return pystray.Menu(*items)
|
||||
|
||||
def _build_menu(self):
|
||||
# Capture current text/submenu at build time; pystray will call
|
||||
# callables each render, but static strings are fine for infrequent
|
||||
# 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()
|
||||
|
||||
# Use a callable for the status item so pystray re-evaluates it
|
||||
# every time the menu is opened — keeps it in sync with the tooltip.
|
||||
return pystray.Menu(
|
||||
pystray.MenuItem(status_text, None, enabled=False),
|
||||
pystray.MenuItem(lambda item: self._status_text(), None, enabled=False),
|
||||
pystray.Menu.SEPARATOR,
|
||||
pystray.MenuItem("Units", units_submenu),
|
||||
pystray.MenuItem("Units", lambda item: self._build_units_submenu()),
|
||||
pystray.Menu.SEPARATOR,
|
||||
pystray.MenuItem("Settings...", self._open_settings),
|
||||
pystray.MenuItem("Open Log Folder", self._open_logs),
|
||||
|
||||
Reference in New Issue
Block a user