mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-27 11:56:05 +02:00
Fix js get and close store
This commit is contained in:
@@ -79,10 +79,6 @@
|
||||
],
|
||||
"deny": ["$APPDATA/db/*.stronghold"]
|
||||
},
|
||||
"store:allow-entries",
|
||||
"store:allow-get",
|
||||
"store:allow-set",
|
||||
"store:allow-save",
|
||||
"store:allow-load"
|
||||
"store:default"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ pub fn run() {
|
||||
.user_agent(&format!("Tauri API - {}", std::env::consts::OS))
|
||||
.title("Tauri API Validation")
|
||||
.inner_size(1000., 800.)
|
||||
.min_inner_size(600., 400.);
|
||||
.min_inner_size(600., 400.)
|
||||
.visible(false);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
||||
@@ -7,15 +7,23 @@
|
||||
let key;
|
||||
let value;
|
||||
|
||||
const store = new LazyStore("cache.json");
|
||||
let store = new LazyStore("cache.json");
|
||||
let cache = {};
|
||||
|
||||
onMount(async () => {
|
||||
const values = await store.entries();
|
||||
for (const [key, value] of values) {
|
||||
cache[key] = value;
|
||||
async function refreshEntries() {
|
||||
try {
|
||||
const values = await store.entries();
|
||||
cache = {};
|
||||
for (const [key, value] of values) {
|
||||
cache[key] = value;
|
||||
}
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
cache = cache;
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await refreshEntries();
|
||||
});
|
||||
|
||||
async function write(key, value) {
|
||||
@@ -23,11 +31,33 @@
|
||||
await store.set(key, value);
|
||||
const v = await store.get(key);
|
||||
cache[key] = v;
|
||||
cache = cache;
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function reset() {
|
||||
try {
|
||||
await store.reset();
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
await refreshEntries();
|
||||
}
|
||||
|
||||
async function close() {
|
||||
try {
|
||||
await store.close();
|
||||
onMessage("Store is now closed, any new operations will now errors out");
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
function reopen() {
|
||||
store = new LazyStore("cache.json");
|
||||
onMessage("We made a new `LazyStore` instance, operations will now work");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col childre:grow gap-1">
|
||||
@@ -42,7 +72,12 @@
|
||||
<input class="grow input" bind:value />
|
||||
</div>
|
||||
|
||||
<button class="btn" on:click={() => write(key, value)}> Write </button>
|
||||
<div>
|
||||
<button class="btn" on:click={() => write(key, value)}>Write</button>
|
||||
<button class="btn" on:click={() => reset()}>Reset</button>
|
||||
<button class="btn" on:click={() => close()}>Close</button>
|
||||
<button class="btn" on:click={() => reopen()}>Re-open</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user