feat(gui): Use inbuild LazyStore feature of @tauri-apps/plugin-store (#150)

This commit is contained in:
binarybaron 2024-11-10 20:46:24 +01:00 committed by GitHub
parent 8c3adbf1ab
commit a116c27785
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 21 deletions

16
Cargo.lock generated
View file

@ -7872,9 +7872,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "2.0.3" version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd96d46534b10765ce0c6208f9451d98ea38636364a41b272d3610c70dd0e4c3" checksum = "5ce2818e803ce3097987296623ed8c0d9f65ed93b4137ff9a83e168bdbf62932"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -8107,9 +8107,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-store" name = "tauri-plugin-store"
version = "2.0.0" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c824c56d35d3aeb97eda0f827c9c419d8fd153a2958f3f40e8e9f34ecc564e6d" checksum = "e9a580be53f04bb62422d239aa798e88522877f58a0d4a0e745f030055a51bb4"
dependencies = [ dependencies = [
"dunce", "dunce",
"log", "log",
@ -8172,9 +8172,9 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime-wry" name = "tauri-runtime-wry"
version = "2.1.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaac63b65df8e85570993eaf93ae1dd73a6fb66d8bd99674ce65f41dc3c63e7d" checksum = "1431602bcc71f2f840ad623915c9842ecc32999b867c4a787d975a17a9625cc6"
dependencies = [ dependencies = [
"gtk", "gtk",
"http 1.1.0", "http 1.1.0",
@ -10057,9 +10057,9 @@ dependencies = [
[[package]] [[package]]
name = "wry" name = "wry"
version = "0.46.0" version = "0.46.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469a3765ecc3e8aa9ccdf3c5a52c82697ec03037cd60494488763880d31a1b3a" checksum = "cd5cdf57c66813d97601181349c63b96994b3074fc3d7a31a8cce96e968e3bbd"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"block2", "block2",

View file

@ -24,7 +24,7 @@
"@tauri-apps/plugin-clipboard-manager": "^2.0.0", "@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0", "@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.0", "@tauri-apps/plugin-shell": "^2.0.0",
"@tauri-apps/plugin-store": "^2.0.0", "@tauri-apps/plugin-store": "2.1.0",
"@tauri-apps/plugin-updater": "^2.0.0", "@tauri-apps/plugin-updater": "^2.0.0",
"humanize-duration": "^3.32.1", "humanize-duration": "^3.32.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",

View file

@ -3,7 +3,7 @@ import { persistReducer, persistStore } from "redux-persist";
import sessionStorage from "redux-persist/lib/storage/session"; import sessionStorage from "redux-persist/lib/storage/session";
import { reducers } from "store/combinedReducer"; import { reducers } from "store/combinedReducer";
import { createMainListeners } from "store/middleware/storeListener"; import { createMainListeners } from "store/middleware/storeListener";
import { createStore } from "@tauri-apps/plugin-store"; import { LazyStore } from "@tauri-apps/plugin-store";
import { getNetworkName } from "store/config"; import { getNetworkName } from "store/config";
// Goal: Maintain application state across page reloads while allowing a clean slate on application restart // Goal: Maintain application state across page reloads while allowing a clean slate on application restart
@ -18,17 +18,15 @@ const rootPersistConfig = {
}; };
// Use Tauri's store plugin for persistent settings // Use Tauri's store plugin for persistent settings
const tauriStore = createStore(`${getNetworkName()}_settings.bin`, { const tauriStore = new LazyStore(`${getNetworkName()}_settings.bin`);
autoSave: 1000 as unknown as boolean,
});
// Configure how settings are stored and retrieved using Tauri's storage // Configure how settings are stored and retrieved using Tauri's storage
const settingsPersistConfig = { const settingsPersistConfig = {
key: "settings", key: "settings",
storage: { storage: {
getItem: async (key: string) => (await tauriStore).get(key), getItem: async (key: string) => tauriStore.get(key),
setItem: async (key: string, value: unknown) => (await tauriStore).set(key, value), setItem: async (key: string, value: unknown) => tauriStore.set(key, value),
removeItem: async (key: string) => (await tauriStore).delete(key), removeItem: async (key: string) => tauriStore.delete(key),
}, },
}; };

View file

@ -902,10 +902,10 @@
dependencies: dependencies:
"@tauri-apps/api" "^2.0.0" "@tauri-apps/api" "^2.0.0"
"@tauri-apps/plugin-store@^2.0.0": "@tauri-apps/plugin-store@2.1.0":
version "2.0.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-store/-/plugin-store-2.0.0.tgz#7563bff85795bc501ac606dab0c329760ef28134" resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-store/-/plugin-store-2.1.0.tgz#02d58e068e52c314417a7df34f3c39eb2b151aa8"
integrity sha512-l4xsbxAXrKGdBdYNNswrLfcRv3v1kOatdycOcVPYW+jKwkznCr1HEOrPXkPhXsZLSLyYmNXpgfOmdSZNmcykDg== integrity sha512-GADqrc17opUKYIAKnGHIUgEeTZ2wJGu1ZITKQ1WMuOFdv8fvXRFBAqsqPjE3opgWohbczX6e1NpwmZK1AnuWVw==
dependencies: dependencies:
"@tauri-apps/api" "^2.0.0" "@tauri-apps/api" "^2.0.0"

View file

@ -25,7 +25,7 @@ tauri-plugin-clipboard-manager = "2.0"
tauri-plugin-devtools = "2.0" tauri-plugin-devtools = "2.0"
tauri-plugin-process = "2.0" tauri-plugin-process = "2.0"
tauri-plugin-shell = "2.0" tauri-plugin-shell = "2.0"
tauri-plugin-store = "2.0" tauri-plugin-store = "2.1.0"
tauri-plugin-updater = "2.0.2" tauri-plugin-updater = "2.0.2"
tracing = "0.1" tracing = "0.1"