Skip to content

Linux: system tray and minimize to tray via ksni - #187

Merged
teamclouday merged 2 commits into
teamclouday:mainfrom
MrWeez:main
Nov 5, 2026
Merged

teamclouday merged 2 commits into
teamclouday:mainfrom
MrWeez:main

Conversation

@MrWeez

@MrWeez MrWeez commented Oct 21, 2026 •

Copy link
Copy Markdown

Summary

This adds a system tray and "minimize to tray" behavior on Linux, which was previously disabled.

Commit 66be82e ("exclude system tray for Linux") disabled the tray on Linux because the tray-icon crate requires a GTK/libappindicator event loop, which conflicts with the cosmic/iced event loop. That also meant closing the window quit the app entirely, and the start_minimized setting did nothing on Linux.

Approach

Instead of re-enabling tray-icon on Linux, this PR adds a second Linux-only backend for the tray using ksni (a pure Rust implementation of the freedesktop/KDE StatusNotifierItem specification):

  • No GTK/libappindicator dependency, so no event loop conflict with cosmic/winit - the tray service runs on its own thread with its own single-threaded tokio runtime (the crate's default tokio feature, and there is no zbus feature-mixing risk since notify-rust uses zbus 3.x while ksni uses zbus 5.x, which are separate crates).
  • Works in AppImage distributions (relevant since the visual icon is rendered from the bundled SVG into ARGB32 pixmaps at 32px and 64px, so no icon theme lookup is needed).
  • The shared tray API (SystemTray::new, update_menu_state, SystemTrayStream::sub) is unchanged, so app.rs mostly drops #[cfg(not(target_os = "linux"))] gates.

Behavior changes on Linux

  • Closing the window now hides it to the tray instead of exiting the app, so streaming continues in the background (mirror of the Windows/macOS behavior). The tray menu still has Exit, and launching a second instance still brings the window back via the existing single-instance IPC.
  • The Start minimized setting now works on Linux: on this platform the app has no "launched automatically" code path (the Linux version of start_at_login is an unimplemented todo!()), so the setting previously could never apply. It is now honored unconditionally.
  • One state persistence fix included in the second commit: the connect/disconnect menu items were initially inverted (a double negation between the disconnected flag and the menu enable states), so Connect stayed enabled while already connected.

Caveats

  • On GNOME, the tray only appears with the AppIndicator/StatusNotifier extension installed. The app still runs in the background and can be recovered by re-running the binary (single instance IPC shows the window); the app itself cannot be exited from the GUI without the tray in that case.
  • Tray menu labels are built with the localization enabled at startup, following the same behavior as the existing tray code on other platforms.

Notes

  • Changes were made using AI assistance (OpenCode with GLM), under human supervision.
  • Tested on Linux (Debian 13, desktop AppImage build): tray icon and menu, connect/disconnect state sync with the main window, hide-to-tray with audio streaming continuing, restore via tray and via second instance launch, and start minimized behavior.

Use ksni (pure Rust DBus StatusNotifierItem) instead of the
tray-icon crate on Linux, since the latter requires a GTK event
loop that conflicts with libcosmic. Window close now hides the
application instead of exiting, so streaming continues in the
background. Reopens via tray menu or launching a second instance.
The connect/disconnect menu items were inverted: two negations
canceled out, so connect stayed enabled while connected. These are
now driven by the same disconnected flag passed to update_menu_state.
Previously, the start minimized setting required being launched
automatically, which never happens on Linux since there is no
autostart implementation, so the setting never applied. Now, on
Linux, the setting always applies.
@teamclouday

Copy link
Copy Markdown
Owner

Thank you for the PR!

@teamclouday
teamclouday merged commit 66abdda into teamclouday:main Nov 5, 2026
3 of 4 checks passed
ID-VerNe pushed a commit to ID-VerNe/AndroidMic that referenced this pull request Nov 16, 2026
Linux: system tray and minimize to tray via ksni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants