From 371dfe5264d49e32cdd265e0c4f647125fe8bdf7 Mon Sep 17 00:00:00 2001 From: Matt Jenkinson <75292329+mattdjenkinson@users.noreply.github.com> Date: Fri, 27 Mar 2026 00:14:10 +0000 Subject: [PATCH] feat: allow config for showing the main app on tray icon click (#5361) Co-authored-by: Jonathan Kelley --- packages/desktop/src/app.rs | 6 +++++- packages/desktop/src/config.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs index 1bb9f96ee..6b1396171 100644 --- a/packages/desktop/src/app.rs +++ b/packages/desktop/src/app.rs @@ -36,6 +36,7 @@ pub(crate) struct App { pub(crate) webviews: HashMap, pub(crate) float_all: bool, pub(crate) show_devtools: bool, + pub(crate) tray_icon_show_window_on_click: bool, /// This single blob of state is shared between all the windows so they have access to the runtime state /// @@ -60,6 +61,8 @@ impl App { .take() .unwrap_or_else(|| EventLoopBuilder::::with_user_event().build()); + let tray_icon_show_window_on_click = cfg.tray_icon_show_window_on_click; + let app = Self { exit_on_last_window_close: cfg.exit_on_last_window_close, disable_dma_buf_on_wayland: cfg.disable_dma_buf_on_wayland, @@ -69,6 +72,7 @@ impl App { unmounted_dom: Cell::new(Some(virtual_dom)), float_all: false, show_devtools: false, + tray_icon_show_window_on_click, cfg: Cell::new(Some(cfg)), shared: Rc::new(SharedContext { event_handlers: WindowEventHandlers::default(), @@ -162,7 +166,7 @@ impl App { button_state: _, } = event { - if button == tray_icon::MouseButton::Left { + if button == tray_icon::MouseButton::Left && self.tray_icon_show_window_on_click { for webview in self.webviews.values() { webview.desktop_context.window.set_visible(true); webview.desktop_context.window.set_focus(); diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index d1281d8c5..78d45bfe9 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -69,6 +69,7 @@ pub struct Config { pub(crate) disable_file_drop_handler: bool, pub(crate) disable_dma_buf_on_wayland: bool, pub(crate) additional_windows_args: Option, + pub(crate) tray_icon_show_window_on_click: bool, #[allow(clippy::type_complexity)] pub(crate) on_window: Option, &mut VirtualDom) + 'static>>, @@ -122,6 +123,7 @@ impl Config { disable_dma_buf_on_wayland: true, on_window: None, additional_windows_args: None, + tray_icon_show_window_on_click: true, } } @@ -338,6 +340,16 @@ impl Config { self.additional_windows_args = Some(additional_args.to_string()); self } + + /// Set whether the main window is shown and focused when the tray icon is left-clicked. + /// + /// Defaults to `true` (preserves current behavior). Set to `false` for tray/menu bar apps + /// that only want to show the context menu when the tray icon is clicked, without + /// activating the main window. + pub fn with_tray_icon_show_window_on_click(mut self, show: bool) -> Self { + self.tray_icon_show_window_on_click = show; + self + } } impl Default for Config {