Skip to content

Commit

Permalink
feat(core): fallback to Window and AppHandle resource table on close (#…
Browse files Browse the repository at this point in the history
…11398)

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
  • Loading branch information
lucasfernog authored Oct 17, 2024
1 parent c8f55b6 commit eb61d44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/resources-close-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---

Fallback to the Window and AppHandle resource table when closing a resource by ID.
9 changes: 8 additions & 1 deletion crates/tauri/src/resources/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ use super::ResourceId;

#[command(root = "crate")]
fn close<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> crate::Result<()> {
webview.resources_table().close(rid)
let mut result = webview.resources_table().close(rid);
if result.is_err() {
result = webview.window().resources_table().close(rid);
if result.is_err() {
result = webview.app_handle().resources_table().close(rid);
}
}
result
}

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

0 comments on commit eb61d44

Please sign in to comment.