fix(core): clear resource table in cleanup_before_exit (#9505)

* Clear resource table in `cleanup_before_exit`

* Add change file

* Update .changes/cleanup-resource-table.md
This commit is contained in:
Tony 2024-04-19 11:50:12 +08:00 committed by GitHub
parent 05088b0679
commit daf018e4f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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();
}
}
}
@ -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)?;
}
}

View File

@ -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()
}
}