Skip to content

Commit 70a1830

Browse files
committed
Revert "remove close_store command since we extend from Resource"
This reverts commit 4a29fc8.
1 parent 4a29fc8 commit 70a1830

8 files changed

Lines changed: 78 additions & 3 deletions

File tree

plugins/store/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/store/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const COMMANDS: &[&str] = &[
66
"load",
77
"get_store",
8+
"close_store",
89
"set",
910
"get",
1011
"has",

plugins/store/guest-js/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ export class Store extends Resource implements IStore {
311311
}
312312
})
313313
}
314+
315+
async close(): Promise<void> {
316+
// The default close on `Resource` can only close resources in the webview's resource table
317+
await invoke('plugin:store|close_store', { rid: this.rid })
318+
}
314319
}
315320

316321
interface IStore {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-close-store"
7+
description = "Enables the close_store command without any pre-configured scope."
8+
commands.allow = ["close_store"]
9+
10+
[[permission]]
11+
identifier = "deny-close-store"
12+
description = "Denies the close_store command without any pre-configured scope."
13+
commands.deny = ["close_store"]

plugins/store/permissions/autogenerated/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All operations are enabled by default.
1111

1212
- `allow-load`
1313
- `allow-get-store`
14+
- `allow-close-store`
1415
- `allow-set`
1516
- `allow-get`
1617
- `allow-has`
@@ -62,6 +63,32 @@ Denies the clear command without any pre-configured scope.
6263
<tr>
6364
<td>
6465

66+
`store:allow-close-store`
67+
68+
</td>
69+
<td>
70+
71+
Enables the close_store command without any pre-configured scope.
72+
73+
</td>
74+
</tr>
75+
76+
<tr>
77+
<td>
78+
79+
`store:deny-close-store`
80+
81+
</td>
82+
<td>
83+
84+
Denies the close_store command without any pre-configured scope.
85+
86+
</td>
87+
</tr>
88+
89+
<tr>
90+
<td>
91+
6592
`store:allow-delete`
6693

6794
</td>

plugins/store/permissions/default.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All operations are enabled by default.
1313
permissions = [
1414
"allow-load",
1515
"allow-get-store",
16+
"allow-close-store",
1617
"allow-set",
1718
"allow-get",
1819
"allow-has",

plugins/store/permissions/schemas/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@
304304
"type": "string",
305305
"const": "deny-clear"
306306
},
307+
{
308+
"description": "Enables the close_store command without any pre-configured scope.",
309+
"type": "string",
310+
"const": "allow-close-store"
311+
},
312+
{
313+
"description": "Denies the close_store command without any pre-configured scope.",
314+
"type": "string",
315+
"const": "deny-close-store"
316+
},
307317
{
308318
"description": "Enables the delete command without any pre-configured scope.",
309319
"type": "string",

plugins/store/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ async fn get_store<R: Runtime>(
133133
Ok(stores.get(&resolve_store_path(&app, path)?).copied())
134134
}
135135

136+
#[tauri::command]
137+
async fn close_store<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
138+
Ok(app.resources_table().close(rid)?)
139+
}
140+
136141
#[tauri::command]
137142
async fn set<R: Runtime>(
138143
app: AppHandle<R>,
@@ -414,8 +419,21 @@ impl Builder {
414419
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
415420
plugin::Builder::new("store")
416421
.invoke_handler(tauri::generate_handler![
417-
load, get_store, set, get, has, delete, clear, reset, keys, values, length,
418-
entries, reload, save,
422+
load,
423+
get_store,
424+
close_store,
425+
set,
426+
get,
427+
has,
428+
delete,
429+
clear,
430+
reset,
431+
keys,
432+
values,
433+
length,
434+
entries,
435+
reload,
436+
save,
419437
])
420438
.setup(move |app_handle, _api| {
421439
app_handle.manage(StoreState {

0 commit comments

Comments
 (0)