From 5ebe1ba5875f445467785f30c7deca529a7ee81c Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Wed, 19 Mar 2025 15:44:37 +0800 Subject: [PATCH] fix: local store loading delay --- src-tauri/capabilities/default.json | 2 ++ src/App.vue | 29 ++++++++++++++++++++++++----- src/components/Mask.vue | 9 ++++++--- src/components/setting/Data.vue | 3 +++ src/store/localStore.ts | 7 ++++++- src/tools/hooks.ts | 1 + src/tools/hotkey.ts | 1 - src/tools/init.ts | 3 --- 8 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index e7b081e..db16f5f 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -20,6 +20,8 @@ "core:window:allow-set-cursor-visible", "core:app:allow-version", "core:app:default", + "core:path:default", + "core:path:allow-resolve-directory", "store:default", "store:allow-get", "store:allow-set", diff --git a/src/App.vue b/src/App.vue index 18d8b43..5c8f765 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,12 +6,15 @@ import { NConfigProvider, NMessageProvider, NDialogProvider, + NSpin, + NFlex, } from "naive-ui"; import { onMounted } from "vue"; -import { primaryInit } from "./tools/init"; +import { useRouter } from "vue-router"; onMounted(() => { - primaryInit(); + const router = useRouter(); + router.replace({ name: "mask" }); }); @@ -21,9 +24,25 @@ onMounted(() => {
- - - + diff --git a/src/components/Mask.vue b/src/components/Mask.vue index 287da83..177a2be 100644 --- a/src/components/Mask.vue +++ b/src/components/Mask.vue @@ -13,12 +13,14 @@ import { import { KeySteeringWheel } from "../tools/keyMappingConfig"; import ScreenStream from "./ScreenStream.vue"; import { useI18n } from "vue-i18n"; -import { secondaryClean, secondaryInit } from "../tools/init"; +import { primaryInit, secondaryClean, secondaryInit } from "../tools/init"; import { cleanAfterimage } from "../tools/tools"; import { NonReactiveStore } from "../store/noneReactiveStore"; import { useRotation } from "../tools/hooks"; import { platform } from "@tauri-apps/plugin-os"; +await primaryInit(); // suspend for primary initialization + const { t } = useI18n(); const store = useGlobalStore(); const router = useRouter(); @@ -62,8 +64,9 @@ onActivated(async () => { await rotation(); }); -onMounted(() => { - secondaryInit().then(() => (initFlag = true)); +onMounted(async () => { + await secondaryInit(); + initFlag = true; }); onUnmounted(() => { diff --git a/src/components/setting/Data.vue b/src/components/setting/Data.vue index 965efc1..e3475aa 100644 --- a/src/components/setting/Data.vue +++ b/src/components/setting/Data.vue @@ -17,6 +17,7 @@ import { onMounted, ref } from "vue"; import { useI18n } from "vue-i18n"; import { LocalStore } from "../../store/localStore"; import ButtonWithTip from "../common/ButtonWithTip.vue"; +import { open } from "@tauri-apps/plugin-shell"; const { t } = useI18n(); @@ -25,6 +26,7 @@ const dialog = useDialog(); const localStoreEntries = ref<[string, unknown][]>([]); const showDataModal = ref(false); const dataModalInputVal = ref(""); + let curDataIndex = -1; onMounted(async () => { @@ -96,6 +98,7 @@ function delLocalStore(key?: string) { /> + {{ LocalStore.path }} {{ $t("pages.Setting.Data.delLocalStore.warning") }} ; + public static path: string; + public static dir: string; static async init() { - this.store = await load("store.json", { autoSave: true }); + this.dir = await appDataDir(); + this.path = await join(this.dir, "store.bin"); + this.store = await load("store.bin", { autoSave: true }); this.vueStore = useGlobalStore(); await initAdbPath(); diff --git a/src/tools/hooks.ts b/src/tools/hooks.ts index 7cf1c64..8bac216 100644 --- a/src/tools/hooks.ts +++ b/src/tools/hooks.ts @@ -9,6 +9,7 @@ import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window"; import { useGlobalStore } from "../store/global"; import { h } from "vue"; import { marked } from "marked"; +import { open } from "@tauri-apps/plugin-shell"; const render = new marked.Renderer(); marked.setOptions({ diff --git a/src/tools/hotkey.ts b/src/tools/hotkey.ts index 46ffadf..33a4e9f 100644 --- a/src/tools/hotkey.ts +++ b/src/tools/hotkey.ts @@ -575,7 +575,6 @@ function addSteeringWheelKeyboardShortcuts( let newPos = calculatedPosList[newPosIndex]; if (newPos.x === curPosX && newPos.y === curPosY) return; - // TODO add config in KeySteeringWheel.vue if (delay) { const { smoothDelay, delayStepLength } = delay; let movePosX = curPosX; diff --git a/src/tools/init.ts b/src/tools/init.ts index 1a233a5..f988f15 100644 --- a/src/tools/init.ts +++ b/src/tools/init.ts @@ -1,4 +1,3 @@ -import { useRouter } from "vue-router"; import { LocalStore } from "../store/localStore"; import { NonReactiveStore } from "../store/noneReactiveStore"; import { useGlobalStore } from "../store/global"; @@ -7,9 +6,7 @@ import { genClientId } from "./tools"; import { getCurrentWindow } from "@tauri-apps/api/window"; export async function primaryInit() { - const router = useRouter(); await LocalStore.init(); - await router.replace({ name: "mask" }); } let unlistenResize = () => {};