Skip to content

Commit

Permalink
Revert "remove close_store command since we extend from Resource"
Browse files Browse the repository at this point in the history
This reverts commit 4a29fc8.
  • Loading branch information
lucasfernog committed Oct 17, 2024
1 parent 4a29fc8 commit 70a1830
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/store/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/store/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const COMMANDS: &[&str] = &[
"load",
"get_store",
"close_store",
"set",
"get",
"has",
Expand Down
5 changes: 5 additions & 0 deletions plugins/store/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ export class Store extends Resource implements IStore {
}
})
}

async close(): Promise<void> {
// The default close on `Resource` can only close resources in the webview's resource table
await invoke('plugin:store|close_store', { rid: this.rid })
}
}

interface IStore {
Expand Down
13 changes: 13 additions & 0 deletions plugins/store/permissions/autogenerated/commands/close_store.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-close-store"
description = "Enables the close_store command without any pre-configured scope."
commands.allow = ["close_store"]

[[permission]]
identifier = "deny-close-store"
description = "Denies the close_store command without any pre-configured scope."
commands.deny = ["close_store"]
27 changes: 27 additions & 0 deletions plugins/store/permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All operations are enabled by default.

- `allow-load`
- `allow-get-store`
- `allow-close-store`
- `allow-set`
- `allow-get`
- `allow-has`
Expand Down Expand Up @@ -62,6 +63,32 @@ Denies the clear command without any pre-configured scope.
<tr>
<td>

`store:allow-close-store`

</td>
<td>

Enables the close_store command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`store:deny-close-store`

</td>
<td>

Denies the close_store command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`store:allow-delete`

</td>
Expand Down
1 change: 1 addition & 0 deletions plugins/store/permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All operations are enabled by default.
permissions = [
"allow-load",
"allow-get-store",
"allow-close-store",
"allow-set",
"allow-get",
"allow-has",
Expand Down
10 changes: 10 additions & 0 deletions plugins/store/permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@
"type": "string",
"const": "deny-clear"
},
{
"description": "Enables the close_store command without any pre-configured scope.",
"type": "string",
"const": "allow-close-store"
},
{
"description": "Denies the close_store command without any pre-configured scope.",
"type": "string",
"const": "deny-close-store"
},
{
"description": "Enables the delete command without any pre-configured scope.",
"type": "string",
Expand Down
22 changes: 20 additions & 2 deletions plugins/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ async fn get_store<R: Runtime>(
Ok(stores.get(&resolve_store_path(&app, path)?).copied())
}

#[tauri::command]
async fn close_store<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
Ok(app.resources_table().close(rid)?)
}

#[tauri::command]
async fn set<R: Runtime>(
app: AppHandle<R>,
Expand Down Expand Up @@ -414,8 +419,21 @@ impl Builder {
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
plugin::Builder::new("store")
.invoke_handler(tauri::generate_handler![
load, get_store, set, get, has, delete, clear, reset, keys, values, length,
entries, reload, save,
load,
get_store,
close_store,
set,
get,
has,
delete,
clear,
reset,
keys,
values,
length,
entries,
reload,
save,
])
.setup(move |app_handle, _api| {
app_handle.manage(StoreState {
Expand Down

0 comments on commit 70a1830

Please sign in to comment.