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
This commit is contained in:
Lucas Fernandes Nogueira 2024-10-17 12:37:35 -03:00 committed by GitHub
parent c8f55b615d
commit eb61d44f9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---
Fallback to the Window and AppHandle resource table when closing a resource by ID.

View File

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