diff --git a/Cargo.lock b/Cargo.lock index 50f1b50..d8e440b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1152,6 +1152,7 @@ dependencies = [ "tauri-plugin-dialog", "tauri-plugin-fs", "tauri-plugin-opener", + "tauri-plugin-store", "tauri-specta", ] @@ -4405,6 +4406,22 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-store" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca1a8ff83c269b115e98726ffc13f9e548a10161544a92ad121d6d0a96e16ea" +dependencies = [ + "dunce", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.16", + "tokio", + "tracing", +] + [[package]] name = "tauri-runtime" version = "2.10.0" diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 8916d68..186a502 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -12,7 +12,8 @@ "@tauri-apps/api": "^2", "@tauri-apps/plugin-dialog": "^2.6.0", "@tauri-apps/plugin-fs": "^2.4.5", - "@tauri-apps/plugin-opener": "^2" + "@tauri-apps/plugin-opener": "^2", + "@tauri-apps/plugin-store": "^2.4.2" }, "devDependencies": { "@sveltejs/adapter-static": "^3.0.6", @@ -1513,6 +1514,15 @@ "@tauri-apps/api": "^2.8.0" } }, + "node_modules/@tauri-apps/plugin-store": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-store/-/plugin-store-2.4.2.tgz", + "integrity": "sha512-0ClHS50Oq9HEvLPhNzTNFxbWVOqoAp3dRvtewQBeqfIQ0z5m3JRnOISIn2ZVPCrQC0MyGyhTS9DWhHjpigQE7A==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.8.0" + } + }, "node_modules/@types/cookie": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", diff --git a/mobile/package.json b/mobile/package.json index f0d58e2..804fe91 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -20,7 +20,8 @@ "@tauri-apps/api": "^2", "@tauri-apps/plugin-dialog": "^2.6.0", "@tauri-apps/plugin-fs": "^2.4.5", - "@tauri-apps/plugin-opener": "^2" + "@tauri-apps/plugin-opener": "^2", + "@tauri-apps/plugin-store": "^2.4.2" }, "devDependencies": { "@sveltejs/adapter-static": "^3.0.6", diff --git a/mobile/src-tauri/Cargo.toml b/mobile/src-tauri/Cargo.toml index 1e33aa9..914ea7a 100644 --- a/mobile/src-tauri/Cargo.toml +++ b/mobile/src-tauri/Cargo.toml @@ -28,6 +28,7 @@ specta = "=2.0.0-rc.22" tauri-plugin-dialog = "2" simd-json = "0.16.0" tauri-plugin-fs = "2" +tauri-plugin-store = "2" [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.15.1" diff --git a/mobile/src-tauri/capabilities/default.json b/mobile/src-tauri/capabilities/default.json index 4f7c3b1..07c1ef6 100644 --- a/mobile/src-tauri/capabilities/default.json +++ b/mobile/src-tauri/capabilities/default.json @@ -9,6 +9,7 @@ "core:default", "opener:default", "dialog:default", - "fs:default" + "fs:default", + "store:default" ] } \ No newline at end of file diff --git a/mobile/src-tauri/src/lib.rs b/mobile/src-tauri/src/lib.rs index 36e9f2e..91234d4 100644 --- a/mobile/src-tauri/src/lib.rs +++ b/mobile/src-tauri/src/lib.rs @@ -97,6 +97,7 @@ pub fn run() { let specta_builder = gen_types(); tauri::Builder::default() + .plugin(tauri_plugin_store::Builder::new().build()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) diff --git a/mobile/src/routes/+page.svelte b/mobile/src/routes/+page.svelte index 2759368..b4f7a94 100644 --- a/mobile/src/routes/+page.svelte +++ b/mobile/src/routes/+page.svelte @@ -4,20 +4,30 @@ import type { LibraryTauri } from '../../bindings' import { readTextFile } from '@tauri-apps/plugin-fs' import Library from './Library.svelte' + import { Store } from '@tauri-apps/plugin-store' - let library = $state(null); let loading = $state(false); let error = $state(''); - // ── Library loading ──────────────────────────────────────────────────────── + const store = await Store.load('settings.json'); + let library = $state(null); + + const saved_library_path = await store.get('library_path') + if (typeof saved_library_path === 'string') { + load_library(saved_library_path) + } async function open_library() { const path = await open({ filters: [{ name: 'JSON', extensions: ['json'] }], }); - if (!path) return; - + if (path) { + load_library(path) + } + } + console.log(await store.entries()) + async function load_library(path: string) { loading = true; library = null error = ''; @@ -26,6 +36,8 @@ const result = await commands.loadLibrary(contents); if (result.status === 'ok') { library = result.data; + store.set('library_path', path) + store.save() } else { error = result.error; } diff --git a/mobile/svelte.config.js b/mobile/svelte.config.js index a7830ea..ed1e327 100644 --- a/mobile/svelte.config.js +++ b/mobile/svelte.config.js @@ -2,17 +2,22 @@ // so we use adapter-static with a fallback to index.html to put the site in SPA mode // See: https://svelte.dev/docs/kit/single-page-apps // See: https://v2.tauri.app/start/frontend/sveltekit/ for more info -import adapter from "@sveltejs/adapter-static"; -import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; +import adapter from '@sveltejs/adapter-static' +import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' /** @type {import('@sveltejs/kit').Config} */ const config = { - preprocess: vitePreprocess(), - kit: { - adapter: adapter({ - fallback: "index.html", - }), - }, -}; + preprocess: vitePreprocess(), + kit: { + adapter: adapter({ + fallback: 'index.html', + }), + }, + compilerOptions: { + experimental: { + async: true, + }, + }, +} -export default config; +export default config