mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-05 12:25:10 +02:00
0c040bcc9a
The Android and iOS support introduced on #1011 is not really supported - the Tauri path API correctly resolves the cache directory on mobile, and we can access those directly using Rust code. This is a breaking change because we no longer uses the same directory to store the files - app_cache_dir returns a different location
56 lines
1.1 KiB
Svelte
56 lines
1.1 KiB
Svelte
<script>
|
|
import { Store } from "@tauri-apps/plugin-store";
|
|
import { onMount } from "svelte";
|
|
|
|
export let onMessage;
|
|
|
|
let key;
|
|
let value;
|
|
|
|
const store = new Store("cache.json");
|
|
let cache = {};
|
|
|
|
onMount(async () => {
|
|
await store.load();
|
|
const values = await store.entries();
|
|
for (const [key, value] of values) {
|
|
cache[key] = value;
|
|
}
|
|
cache = cache;
|
|
});
|
|
|
|
function write(key, value) {
|
|
store
|
|
.set(key, value)
|
|
.then(() => store.get(key))
|
|
.then((v) => {
|
|
cache[key] = v;
|
|
cache = cache;
|
|
})
|
|
.then(() => store.save())
|
|
.catch(onMessage);
|
|
}
|
|
</script>
|
|
|
|
<div class="flex flex-col childre:grow gap-1">
|
|
<div class="flex flex-col flex-row-md gap-4">
|
|
<div class="flex items-center gap-1">
|
|
Key:
|
|
<input class="grow input" bind:value={key} />
|
|
</div>
|
|
|
|
<div class="flex items-center gap-1">
|
|
Value:
|
|
<input class="grow input" bind:value />
|
|
</div>
|
|
|
|
<button class="btn" on:click={() => write(key, value)}> Write </button>
|
|
</div>
|
|
|
|
<div>
|
|
{#each Object.entries(cache) as [k, v]}
|
|
<div>{k} = {v}</div>
|
|
{/each}
|
|
</div>
|
|
</div>
|