feat: add Restart and Shutdown buttons to system tray
Some checks failed
Lint & Test / test (push) Failing after 29s
Some checks failed
Lint & Test / test (push) Failing after 29s
Both actions show a confirmation dialog before proceeding. Restart uses os.execv to re-launch the process in-place. Shutdown stops the server and exits the tray.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user