refactor: ♻️ 优化存储

This commit is contained in:
tsl
2026-04-17 08:58:20 +08:00
parent 8137d414da
commit 13f92f79b6
17 changed files with 443 additions and 182 deletions
+11 -4
View File
@@ -1,11 +1,17 @@
import { load, type Store } from "@tauri-apps/plugin-store";
import {
APP_CONFIG_STORAGE_KEY,
CREDENTIALS_STORAGE_KEY,
STORE_FILE_NAME,
} from "@/constants/store";
let storeInstance: Store | null = null;
async function getStore(): Promise<Store> {
if (!storeInstance) {
storeInstance = await load("config.json", { defaults: {}, autoSave: true });
}
storeInstance ??= await load(STORE_FILE_NAME, {
defaults: {},
autoSave: true,
});
return storeInstance;
}
@@ -37,7 +43,7 @@ export async function migrateFromLocalStorage(): Promise<boolean> {
if (migrated) return false;
let hasMigrated = false;
for (const key of ["crm_credentials", "crm_config"]) {
for (const key of [CREDENTIALS_STORAGE_KEY, APP_CONFIG_STORAGE_KEY]) {
const raw = localStorage.getItem(key);
if (raw) {
try {
@@ -46,6 +52,7 @@ export async function migrateFromLocalStorage(): Promise<boolean> {
hasMigrated = true;
} catch {
/* ignore invalid JSON */
// TODO 换成r-utils解析JSON
}
}
}
+5
View File
@@ -0,0 +1,5 @@
import { getCurrentWindow } from "@tauri-apps/api/window";
export async function hideCurrentWindow() {
await getCurrentWindow().hide();
}