Skip to content

Commit

Permalink
feat(gui): Use inbuild LazyStore feature of @tauri-apps/plugin-store (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron authored Nov 10, 2024
1 parent 8c3adbf commit a116c27
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-process": "^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",
"humanize-duration": "^3.32.1",
"lodash": "^4.17.21",
Expand Down
12 changes: 5 additions & 7 deletions src-gui/src/renderer/store/storeRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { persistReducer, persistStore } from "redux-persist";
import sessionStorage from "redux-persist/lib/storage/session";
import { reducers } from "store/combinedReducer";
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";

// Goal: Maintain application state across page reloads while allowing a clean slate on application restart
Expand All @@ -18,17 +18,15 @@ const rootPersistConfig = {
};

// Use Tauri's store plugin for persistent settings
const tauriStore = createStore(`${getNetworkName()}_settings.bin`, {
autoSave: 1000 as unknown as boolean,
});
const tauriStore = new LazyStore(`${getNetworkName()}_settings.bin`);

// Configure how settings are stored and retrieved using Tauri's storage
const settingsPersistConfig = {
key: "settings",
storage: {
getItem: async (key: string) => (await tauriStore).get(key),
setItem: async (key: string, value: unknown) => (await tauriStore).set(key, value),
removeItem: async (key: string) => (await tauriStore).delete(key),
getItem: async (key: string) => tauriStore.get(key),
setItem: async (key: string, value: unknown) => tauriStore.set(key, value),
removeItem: async (key: string) => tauriStore.delete(key),
},
};

Expand Down
8 changes: 4 additions & 4 deletions src-gui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -902,10 +902,10 @@
dependencies:
"@tauri-apps/api" "^2.0.0"

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

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tauri-plugin-clipboard-manager = "2.0"
tauri-plugin-devtools = "2.0"
tauri-plugin-process = "2.0"
tauri-plugin-shell = "2.0"
tauri-plugin-store = "2.0"
tauri-plugin-store = "2.1.0"
tauri-plugin-updater = "2.0.2"
tracing = "0.1"

Expand Down

0 comments on commit a116c27

Please sign in to comment.