Try to create tray with AppIndicator3
(self)
| 41 | # Silent - the GUI still works without system tray |
| 42 | |
| 43 | def _try_appindicator(self) -> bool: |
| 44 | """Try to create tray with AppIndicator3""" |
| 45 | try: |
| 46 | import gi |
| 47 | |
| 48 | gi.require_version("Gtk", "3.0") |
| 49 | gi.require_version("AppIndicator3", "0.1") |
| 50 | from gi.repository import AppIndicator3, GLib, Gtk |
| 51 | |
| 52 | # Create menu |
| 53 | menu = Gtk.Menu() |
| 54 | |
| 55 | # Menu items |
| 56 | item_show = Gtk.MenuItem(label="📂 Show Window") |
| 57 | item_show.connect( |
| 58 | "activate", lambda w: GLib.idle_add(self.app._show_window) |
| 59 | ) |
| 60 | menu.append(item_show) |
| 61 | |
| 62 | menu.append(Gtk.SeparatorMenuItem()) |
| 63 | |
| 64 | item_start = Gtk.MenuItem(label="▶️ Start") |
| 65 | item_start.connect("activate", lambda w: GLib.idle_add(self.app._start)) |
| 66 | menu.append(item_start) |
| 67 | |
| 68 | item_stop = Gtk.MenuItem(label="⏹️ Stop") |
| 69 | item_stop.connect("activate", lambda w: GLib.idle_add(self.app._stop)) |
| 70 | menu.append(item_stop) |
| 71 | |
| 72 | menu.append(Gtk.SeparatorMenuItem()) |
| 73 | |
| 74 | item_test = Gtk.MenuItem(label="🔍 API Test") |
| 75 | item_test.connect("activate", lambda w: GLib.idle_add(self.app._api_test)) |
| 76 | menu.append(item_test) |
| 77 | |
| 78 | menu.append(Gtk.SeparatorMenuItem()) |
| 79 | |
| 80 | item_quit = Gtk.MenuItem(label="❌ Exit") |
| 81 | item_quit.connect( |
| 82 | "activate", lambda w: GLib.idle_add(self.app._close_completely) |
| 83 | ) |
| 84 | menu.append(item_quit) |
| 85 | |
| 86 | menu.show_all() |
| 87 | |
| 88 | # Create AppIndicator |
| 89 | self.indicator = AppIndicator3.Indicator.new( |
| 90 | "aistudio-proxy", |
| 91 | "network-server", |
| 92 | AppIndicator3.IndicatorCategory.APPLICATION_STATUS, |
| 93 | ) |
| 94 | self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) |
| 95 | self.indicator.set_menu(menu) |
| 96 | self.indicator.set_title("AI Studio Proxy") |
| 97 | |
| 98 | # Run GTK main loop in separate thread |
| 99 | def gtk_main(): |
| 100 | try: |