"""System tray icon and menu for the I2P router. Provides a platform-independent tray icon with status display and quick actions (open console, restart, shutdown). Ported from net.i2p.desktopgui.InternalTrayManager. """ from __future__ import annotations from dataclasses import dataclass, field @dataclass class TrayConfig: """Configuration for the system tray.""" console_url: str = "http://127.0.0.1:7657" tooltip: str = "I2P Router" @dataclass class MenuItem: """A menu item in the tray context menu.""" label: str = "" action: str = "" is_separator: bool = False @classmethod def separator(cls) -> MenuItem: return cls(is_separator=True) class TrayMenu: """System tray context menu.""" def __init__(self, items: list[MenuItem] | None = None) -> None: if items is not None: self.items = items else: self.items = self._default_items() @staticmethod def _default_items() -> list[MenuItem]: return [ MenuItem(label="Open Console", action="open_console"), MenuItem.separator(), MenuItem(label="Restart", action="restart"), MenuItem(label="Shutdown Gracefully", action="shutdown_graceful"), MenuItem(label="Shutdown Immediately", action="shutdown"), MenuItem.separator(), MenuItem(label="Cancel Shutdown", action="cancel_shutdown"), ] @staticmethod def status_text(state: str, peer_count: int) -> str: """Generate status text for the tooltip.""" return f"I2P: {state.capitalize()} — {peer_count} peers"