From dbe0d21b6fdc0f7d4c7b5e099cef805b60ef203e Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 31 Aug 2021 14:53:27 -0300 Subject: [PATCH] fix(core): initialize system tray before app windows --- .changes/fix-tray-command.md | 5 ++++ core/tauri/src/app.rs | 46 ++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 .changes/fix-tray-command.md diff --git a/.changes/fix-tray-command.md b/.changes/fix-tray-command.md new file mode 100644 index 000000000..6de01cedc --- /dev/null +++ b/.changes/fix-tray-command.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Initialize system tray before windows so `tray_handle` can be accessed on command handlers. diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 530b5ceee..e5acbbab3 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -914,29 +914,6 @@ impl Builder { }, }; - app.manager.initialize_plugins(&app.handle())?; - - let pending_labels = self - .pending_windows - .iter() - .map(|p| p.label.clone()) - .collect::>(); - - #[cfg(feature = "updater")] - let mut main_window = None; - - for pending in self.pending_windows { - let pending = app - .manager - .prepare_window(app.handle.clone(), pending, &pending_labels)?; - let detached = app.runtime.as_ref().unwrap().create_window(pending)?; - let _window = app.manager.attach_window(app.handle(), detached); - #[cfg(feature = "updater")] - if main_window.is_none() { - main_window = Some(_window); - } - } - #[cfg(feature = "system-tray")] if let Some(system_tray) = self.system_tray { let mut ids = HashMap::new(); @@ -1027,6 +1004,29 @@ impl Builder { } } + app.manager.initialize_plugins(&app.handle())?; + + let pending_labels = self + .pending_windows + .iter() + .map(|p| p.label.clone()) + .collect::>(); + + #[cfg(feature = "updater")] + let mut main_window = None; + + for pending in self.pending_windows { + let pending = app + .manager + .prepare_window(app.handle.clone(), pending, &pending_labels)?; + let detached = app.runtime.as_ref().unwrap().create_window(pending)?; + let _window = app.manager.attach_window(app.handle(), detached); + #[cfg(feature = "updater")] + if main_window.is_none() { + main_window = Some(_window); + } + } + (self.setup)(&mut app).map_err(|e| crate::Error::Setup(e))?; #[cfg(feature = "updater")]