feat: add configurable close behavior (hide to tray / exit) with settings UI - #421
Open
LeonardW-sl wants to merge 2 commits into
Open
feat: add configurable close behavior (hide to tray / exit) with settings UI#421LeonardW-sl wants to merge 2 commits into
LeonardW-sl wants to merge 2 commits into
Conversation
On Linux, Tauri's tray build() succeeds even when the desktop session does not provide a StatusNotifierWatcher (notably GNOME 45+ without an AppIndicator extension). In that case the tray icon is silently invisible and hiding the main window would leave the user with no way to recover it. Previously codeg avoided this by unconditionally returning false from can_hide_to_tray() on Linux, which prevented hide-to-tray even on KDE, XFCE, Cinnamon, Budgie, and GNOME-with-AppIndicator — all of which have a working tray. Fix: detect the actual tray availability at install_tray_icon() time by querying D-Bus for org.kde.StatusNotifierWatcher. Only set TRAY_AVAILABLE when the service is present, so the close handler hides the window on fully capable desktops and exits otherwise.
There was a problem hiding this comment.
Pull request overview
This PR updates the Tauri (desktop) tray-availability logic so Linux sessions with a real, usable system tray can safely “hide to tray” on window close, while preserving the existing fail-safe behavior on desktops where the tray icon would be invisible.
Changes:
- Add a Linux-only D-Bus check (via
gdbus call org.freedesktop.DBus.NameHasOwner) to detect whetherorg.kde.StatusNotifierWatcheris present. - Stop unconditionally disabling hide-to-tray on Linux; instead, set
TRAY_AVAILABLEonly when the watcher is detected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ings UI Add a new setting to let users choose what happens when the main window close button is clicked: - Hide to tray (background) — default. Window hides to system tray if available; falls back to exit if no tray is present. - Exit application — always exits on close, regardless of tray. Backend changes: - New CloseAction enum + SystemCloseSettings model - load_system_close_settings/get_system_close_settings/update_system_close_settings - Close button handler reads stored setting instead of checking can_hide_to_tray() alone Frontend changes: - CloseBehaviorSettings component with radio-button UI - Integrated into GeneralSettings page - All 10 locales updated with 4 new strings - 3 new unit tests covering load, save, and save-failure revert All new items gated behind tauri-runtime feature to keep sidecar builds clean. 3482 existing tests pass, no lint warnings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Linux (and other platforms), clicking the main window's close button always exits the entire application. There is no way to minimize to the system tray and keep the app running in the background.
The existing
can_hide_to_tray()check was already able to detect tray availability, but the close button simply checkedcan_hide_to_tray()without consulting any user preference — if the tray was available, it always hid; if not, it always exited. There was no UI for the user to choose their preferred behavior.Solution
Add a configurable close-behavior setting with two options:
Changes
Backend (Rust):
models/system.rs: NewCloseActionenum (HideToTray/Exit) andSystemCloseSettingsstruct, persisted viaapp_metadata_service.commands/system_settings.rs:load_system_close_settings,get_system_close_settings,update_system_close_settings— all gated behindtauri-runtimeto avoid dead_code warnings in sidecar builds.lib.rs: Close button handler reads the stored setting and usesCloseAction::HideToTray && can_hide_to_tray()instead ofcan_hide_to_tray()alone.Frontend (TypeScript/React):
lib/types.ts:CloseActiontype andSystemCloseSettingsinterface.lib/api.ts:getSystemCloseSettings()/updateSystemCloseSettings()transport wrappers.components/settings/close-behavior-settings.tsx: Radio-button UI with loading/saving states and error toast.components/settings/general-settings.tsx: Integrates the new section.i18n/messages/*.json: All 10 locales updated with the 4 new strings.Testing
cargo build --no-default-features --bin codeg-mcp).cargo build --release --bin codeg).can_hide_to_tray()returns false, so both settings exit the app (no stranded process).