diff --git a/server/src/wled_controller/tray.py b/server/src/wled_controller/tray.py index a62ca1f..c45ba68 100644 --- a/server/src/wled_controller/tray.py +++ b/server/src/wled_controller/tray.py @@ -1,7 +1,10 @@ """System tray icon for LED Grab (Windows).""" +import os +import sys import webbrowser from pathlib import Path +from tkinter import messagebox from typing import Callable from PIL import Image @@ -41,7 +44,8 @@ class TrayManager: menu = pystray.Menu( pystray.MenuItem("Show UI", self._show_ui, default=True), pystray.Menu.SEPARATOR, - pystray.MenuItem("Exit", self._exit), + pystray.MenuItem("Restart", self._restart), + pystray.MenuItem("Shutdown", self._shutdown), ) self._icon = pystray.Icon( @@ -56,7 +60,16 @@ class TrayManager: def _show_ui(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None: webbrowser.open(f"http://localhost:{self._port}") - def _exit(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None: + def _restart(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None: + if not messagebox.askyesno("LED Grab", "Restart the server?"): + return + self._icon.stop() + self._on_exit() + os.execv(sys.executable, [sys.executable, "-m", "wled_controller"]) + + def _shutdown(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None: + if not messagebox.askyesno("LED Grab", "Shut down the server?"): + return self._on_exit() self._icon.stop()