Skip to content

Commit 4cd0bb8

Browse files
Fix tray visibility toggle crash (#5839)
Use Tauri tray visibility APIs instead of removing the tray icon from the IPC worker thread.
1 parent 1204160 commit 4cd0bb8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

plugins/tray/src/ext.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,22 @@ impl<'a, M: tauri::Manager<tauri::Wry>> Tray<'a, tauri::Wry, M> {
136136
let app = self.manager.app_handle();
137137

138138
if visible {
139-
self.create_tray_menu()?;
139+
if let Some(tray) = app.tray_by_id(TRAY_ID) {
140+
tray.set_visible(true)?;
141+
} else {
142+
self.create_tray_menu()?;
143+
}
140144
Self::refresh_icon(app)?;
141145
} else {
142146
if let Ok(mut task) = ANIMATION_TASK.lock()
143147
&& let Some(handle) = task.take()
144148
{
145149
handle.abort();
146150
}
147-
let _ = app.remove_tray_by_id(TRAY_ID);
151+
152+
if let Some(tray) = app.tray_by_id(TRAY_ID) {
153+
tray.set_visible(false)?;
154+
}
148155
}
149156

150157
Ok(())

0 commit comments

Comments
 (0)