refactor: ♻️ 优化存储
This commit is contained in:
+11
-4
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
|
||||
export async function hideCurrentWindow() {
|
||||
await getCurrentWindow().hide();
|
||||
}
|
||||
Reference in New Issue
Block a user