From eb61d44f9fc1be591c3d10a6ac1451aa39e6a77b Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 17 Oct 2024 12:37:35 -0300 Subject: [PATCH] feat(core): fallback to Window and AppHandle resource table on close (#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 https://github.com/tauri-apps/plugins-workspace/pull/1860#issuecomment-2419175001 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 --- .changes/resources-close-fallback.md | 5 +++++ crates/tauri/src/resources/plugin.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changes/resources-close-fallback.md diff --git a/.changes/resources-close-fallback.md b/.changes/resources-close-fallback.md new file mode 100644 index 000000000..2a7c15eec --- /dev/null +++ b/.changes/resources-close-fallback.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:enhance +--- + +Fallback to the Window and AppHandle resource table when closing a resource by ID. diff --git a/crates/tauri/src/resources/plugin.rs b/crates/tauri/src/resources/plugin.rs index 7786fe74e..cf8288612 100644 --- a/crates/tauri/src/resources/plugin.rs +++ b/crates/tauri/src/resources/plugin.rs @@ -12,7 +12,14 @@ use super::ResourceId; #[command(root = "crate")] fn close(webview: Webview, 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() -> TauriPlugin {