feat: allow config for showing the main app on tray icon click (#5361)

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Matt JenkinsonandJonathan Kelley authored and GitHub committed 2026-03-26 17:14:10 -07:00
1 parent b94f8c6b5f
commit 371dfe5264
2 files changed
+17 -1

No files matched your search

+5 -1
View File
@@ -36,6 +36,7 @@ pub(crate) struct App {
pub(crate) webviews: HashMap<WindowId, WebviewInstance>,
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::<UserWindowEvent>::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();
+12
View File
@@ -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<String>,
pub(crate) tray_icon_show_window_on_click: bool,
#[allow(clippy::type_complexity)]
pub(crate) on_window: Option<Box<dyn FnMut(Arc<Window>, &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 {