Skip to content

Commit cefbadd

Browse files
committed
feat(core): fallback to Window and AppHandle resource table on close
this changes the resource plugin close() API to fallback to the parent window and AppHandle resource tables, letting the JS to delete global resources. The need for this was brought up on tauri-apps/plugins-workspace#1860 (comment) the store plugin stores the resources in the AppHandle, and we want the existing close() API to work on global resources otherwise every consumer needs their own resource close commands
1 parent 2e88633 commit cefbadd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changes/resources-close-fallback.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:enhance
3+
---
4+
5+
Fallback to the Window and AppHandle resource table when closing a resource by ID.

crates/tauri/src/resources/plugin.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ use super::ResourceId;
1212

1313
#[command(root = "crate")]
1414
fn close<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> crate::Result<()> {
15-
webview.resources_table().close(rid)
15+
let mut result = webview.resources_table().close(rid);
16+
if result.is_err() {
17+
result = webview.window().resources_table().close(rid);
18+
if result.is_err() {
19+
result = webview.app_handle().resources_table().close(rid);
20+
}
21+
}
22+
result
1623
}
1724

1825
pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {

0 commit comments

Comments
 (0)