Save settings (unsafe)

This commit is contained in:
2026-02-21 16:17:50 +01:00
parent c1810aa6b7
commit feda048f1c
9 changed files with 118 additions and 5 deletions

View File

@@ -0,0 +1,33 @@
import { load, type Store } from '@tauri-apps/plugin-store';
let storePromise: Promise<Store> | null = null;
function getStore(): Promise<Store> {
if (!storePromise) {
storePromise = load('store.json', {
autoSave: false,
defaults: {},
});
}
return storePromise;
}
export function useStore() {
const setValue = async <T>(key: string, value: T) => {
console.log('setValue',key,value);
const store = await getStore();
await store.set(key, value);
};
const getValue = async <T>(key: string) => {
console.log('getValue',key);
const store = await getStore();
return store.get<T>(key);
};
return {
setValue,
getValue,
};
}