A Python port of the Invisible Internet Project (I2P)
at main 57 lines 1.6 kB view raw
1"""System tray icon and menu for the I2P router. 2 3Provides a platform-independent tray icon with status display 4and quick actions (open console, restart, shutdown). 5 6Ported from net.i2p.desktopgui.InternalTrayManager. 7""" 8 9from __future__ import annotations 10 11from dataclasses import dataclass, field 12 13 14@dataclass 15class TrayConfig: 16 """Configuration for the system tray.""" 17 console_url: str = "http://127.0.0.1:7657" 18 tooltip: str = "I2P Router" 19 20 21@dataclass 22class MenuItem: 23 """A menu item in the tray context menu.""" 24 label: str = "" 25 action: str = "" 26 is_separator: bool = False 27 28 @classmethod 29 def separator(cls) -> MenuItem: 30 return cls(is_separator=True) 31 32 33class TrayMenu: 34 """System tray context menu.""" 35 36 def __init__(self, items: list[MenuItem] | None = None) -> None: 37 if items is not None: 38 self.items = items 39 else: 40 self.items = self._default_items() 41 42 @staticmethod 43 def _default_items() -> list[MenuItem]: 44 return [ 45 MenuItem(label="Open Console", action="open_console"), 46 MenuItem.separator(), 47 MenuItem(label="Restart", action="restart"), 48 MenuItem(label="Shutdown Gracefully", action="shutdown_graceful"), 49 MenuItem(label="Shutdown Immediately", action="shutdown"), 50 MenuItem.separator(), 51 MenuItem(label="Cancel Shutdown", action="cancel_shutdown"), 52 ] 53 54 @staticmethod 55 def status_text(state: str, peer_count: int) -> str: 56 """Generate status text for the tooltip.""" 57 return f"I2P: {state.capitalize()}{peer_count} peers"