Skip to content

Commit

Permalink
fix(core): clear resource table in cleanup_before_exit (#9505)
Browse files Browse the repository at this point in the history
* Clear resource table in `cleanup_before_exit`

* Add change file

* Update .changes/cleanup-resource-table.md
  • Loading branch information
Legend-Master committed Apr 19, 2024
1 parent 05088b0 commit daf018e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/cleanup-resource-table.md
@@ -0,0 +1,5 @@
---
tauri: patch:bug
---

Fix resource tables not cleaned up on exit which causes tray icon inside resource tables not cleaned up on exit
10 changes: 8 additions & 2 deletions core/tauri/src/app.rs
Expand Up @@ -754,6 +754,13 @@ macro_rules! shared_app_impl {
pub fn cleanup_before_exit(&self) {
#[cfg(all(desktop, feature = "tray-icon"))]
self.manager.tray.icons.lock().unwrap().clear();
self.manager.resources_table().clear();
for (_, window) in self.manager.windows().iter() {
window.resources_table().clear();
}
for (_, webview) in self.manager.webviews().iter() {
webview.resources_table().clear();
}
}
}

Expand Down Expand Up @@ -1700,8 +1707,7 @@ tauri::Builder::default()
if let Some(tooltip) = &tray_config.tooltip {
tray = tray.tooltip(tooltip);
}
let tray = tray.build(handle)?;
app.manager.tray.icons.lock().unwrap().push(tray);
tray.build(handle)?;
}
}

Expand Down
6 changes: 6 additions & 0 deletions core/tauri/src/resources/mod.rs
Expand Up @@ -209,4 +209,10 @@ impl ResourceTable {
.ok_or_else(|| crate::Error::BadResourceId(rid))
.map(|resource| resource.close())
}

/// Removes and frees all resources stored. Note that the
/// resource's `close()` method is *not* called.
pub(crate) fn clear(&mut self) {
self.index.clear()
}
}

0 comments on commit daf018e

Please sign in to comment.