Skip to content

Commit daf018e

Browse files
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
1 parent 05088b0 commit daf018e

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

.changes/cleanup-resource-table.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:bug
3+
---
4+
5+
Fix resource tables not cleaned up on exit which causes tray icon inside resource tables not cleaned up on exit

core/tauri/src/app.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ macro_rules! shared_app_impl {
754754
pub fn cleanup_before_exit(&self) {
755755
#[cfg(all(desktop, feature = "tray-icon"))]
756756
self.manager.tray.icons.lock().unwrap().clear();
757+
self.manager.resources_table().clear();
758+
for (_, window) in self.manager.windows().iter() {
759+
window.resources_table().clear();
760+
}
761+
for (_, webview) in self.manager.webviews().iter() {
762+
webview.resources_table().clear();
763+
}
757764
}
758765
}
759766

@@ -1700,8 +1707,7 @@ tauri::Builder::default()
17001707
if let Some(tooltip) = &tray_config.tooltip {
17011708
tray = tray.tooltip(tooltip);
17021709
}
1703-
let tray = tray.build(handle)?;
1704-
app.manager.tray.icons.lock().unwrap().push(tray);
1710+
tray.build(handle)?;
17051711
}
17061712
}
17071713

core/tauri/src/resources/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,10 @@ impl ResourceTable {
209209
.ok_or_else(|| crate::Error::BadResourceId(rid))
210210
.map(|resource| resource.close())
211211
}
212+
213+
/// Removes and frees all resources stored. Note that the
214+
/// resource's `close()` method is *not* called.
215+
pub(crate) fn clear(&mut self) {
216+
self.index.clear()
217+
}
212218
}

0 commit comments

Comments
 (0)