Skip to content

Commit a03b855

Browse files
authored
fix(core): tray not closing on Windows (#3351)
1 parent af44bf8 commit a03b855

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime-wry": patch
4+
---
5+
6+
Reimplement `remove_system_tray` on Windows to drop the `SystemTray` to run its cleanup code.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ pub enum TrayMessage {
993993
UpdateIcon(Icon),
994994
#[cfg(target_os = "macos")]
995995
UpdateIconAsTemplate(bool),
996+
Close,
996997
}
997998

998999
#[derive(Debug, Clone)]
@@ -1565,7 +1566,7 @@ impl RuntimeHandle for WryHandle {
15651566
#[cfg(all(windows, feature = "system-tray"))]
15661567
/// Deprecated. (not needed anymore)
15671568
fn remove_system_tray(&self) -> Result<()> {
1568-
Ok(())
1569+
send_user_message(&self.context, Message::Tray(TrayMessage::Close))
15691570
}
15701571
}
15711572

@@ -2205,6 +2206,11 @@ fn handle_user_message(
22052206
tray.lock().unwrap().set_icon_as_template(is_template);
22062207
}
22072208
}
2209+
TrayMessage::Close => {
2210+
*tray_context.tray.lock().unwrap() = None;
2211+
tray_context.listeners.lock().unwrap().clear();
2212+
tray_context.items.lock().unwrap().clear();
2213+
}
22082214
},
22092215
Message::GlobalShortcut(message) => match message {
22102216
GlobalShortcutMessage::IsRegistered(accelerator, tx) => tx

0 commit comments

Comments
 (0)