fix: local store loading delay

This commit is contained in:
AkiChase 2025-03-19 15:44:37 +08:00
parent 812244cbab
commit 5ebe1ba587
8 changed files with 42 additions and 13 deletions

View File

@ -20,6 +20,8 @@
"core:window:allow-set-cursor-visible", "core:window:allow-set-cursor-visible",
"core:app:allow-version", "core:app:allow-version",
"core:app:default", "core:app:default",
"core:path:default",
"core:path:allow-resolve-directory",
"store:default", "store:default",
"store:allow-get", "store:allow-get",
"store:allow-set", "store:allow-set",

View File

@ -6,12 +6,15 @@ import {
NConfigProvider, NConfigProvider,
NMessageProvider, NMessageProvider,
NDialogProvider, NDialogProvider,
NSpin,
NFlex,
} from "naive-ui"; } from "naive-ui";
import { onMounted } from "vue"; import { onMounted } from "vue";
import { primaryInit } from "./tools/init"; import { useRouter } from "vue-router";
onMounted(() => { onMounted(() => {
primaryInit(); const router = useRouter();
router.replace({ name: "mask" });
}); });
</script> </script>
@ -21,9 +24,25 @@ onMounted(() => {
<NDialogProvider> <NDialogProvider>
<Header /> <Header />
<RouterView v-slot="{ Component }"> <RouterView v-slot="{ Component }">
<KeepAlive> <template v-if="Component">
<component :is="Component" /> <KeepAlive>
</KeepAlive> <Suspense>
<component :is="Component" />
<template #fallback>
<NFlex
justify="center"
align="center"
style="
grid-area: content;
background-color: var(--content-bg-color);
"
>
<NSpin :size="75" />
</NFlex>
</template>
</Suspense>
</KeepAlive>
</template>
</RouterView> </RouterView>
<Sidebar /> <Sidebar />
</NDialogProvider> </NDialogProvider>

View File

@ -13,12 +13,14 @@ import {
import { KeySteeringWheel } from "../tools/keyMappingConfig"; import { KeySteeringWheel } from "../tools/keyMappingConfig";
import ScreenStream from "./ScreenStream.vue"; import ScreenStream from "./ScreenStream.vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { secondaryClean, secondaryInit } from "../tools/init"; import { primaryInit, secondaryClean, secondaryInit } from "../tools/init";
import { cleanAfterimage } from "../tools/tools"; import { cleanAfterimage } from "../tools/tools";
import { NonReactiveStore } from "../store/noneReactiveStore"; import { NonReactiveStore } from "../store/noneReactiveStore";
import { useRotation } from "../tools/hooks"; import { useRotation } from "../tools/hooks";
import { platform } from "@tauri-apps/plugin-os"; import { platform } from "@tauri-apps/plugin-os";
await primaryInit(); // suspend for primary initialization
const { t } = useI18n(); const { t } = useI18n();
const store = useGlobalStore(); const store = useGlobalStore();
const router = useRouter(); const router = useRouter();
@ -62,8 +64,9 @@ onActivated(async () => {
await rotation(); await rotation();
}); });
onMounted(() => { onMounted(async () => {
secondaryInit().then(() => (initFlag = true)); await secondaryInit();
initFlag = true;
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@ -17,6 +17,7 @@ import { onMounted, ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { LocalStore } from "../../store/localStore"; import { LocalStore } from "../../store/localStore";
import ButtonWithTip from "../common/ButtonWithTip.vue"; import ButtonWithTip from "../common/ButtonWithTip.vue";
import { open } from "@tauri-apps/plugin-shell";
const { t } = useI18n(); const { t } = useI18n();
@ -25,6 +26,7 @@ const dialog = useDialog();
const localStoreEntries = ref<[string, unknown][]>([]); const localStoreEntries = ref<[string, unknown][]>([]);
const showDataModal = ref(false); const showDataModal = ref(false);
const dataModalInputVal = ref(""); const dataModalInputVal = ref("");
let curDataIndex = -1; let curDataIndex = -1;
onMounted(async () => { onMounted(async () => {
@ -96,6 +98,7 @@ function delLocalStore(key?: string) {
/> />
</NFlex> </NFlex>
</NFlex> </NFlex>
<NButton text @click="open(LocalStore.dir)">{{ LocalStore.path }}</NButton>
<NP>{{ $t("pages.Setting.Data.delLocalStore.warning") }}</NP> <NP>{{ $t("pages.Setting.Data.delLocalStore.warning") }}</NP>
<NList class="data-list" hoverable clickable> <NList class="data-list" hoverable clickable>
<NListItem <NListItem

View File

@ -12,13 +12,18 @@ import {
LogicalSize, LogicalSize,
primaryMonitor, primaryMonitor,
} from "@tauri-apps/api/window"; } from "@tauri-apps/api/window";
import { appDataDir, join } from "@tauri-apps/api/path";
export class LocalStore { export class LocalStore {
public static store: Store; public static store: Store;
public static vueStore: ReturnType<typeof useGlobalStore>; public static vueStore: ReturnType<typeof useGlobalStore>;
public static path: string;
public static dir: string;
static async init() { 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(); this.vueStore = useGlobalStore();
await initAdbPath(); await initAdbPath();

View File

@ -9,6 +9,7 @@ import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
import { useGlobalStore } from "../store/global"; import { useGlobalStore } from "../store/global";
import { h } from "vue"; import { h } from "vue";
import { marked } from "marked"; import { marked } from "marked";
import { open } from "@tauri-apps/plugin-shell";
const render = new marked.Renderer(); const render = new marked.Renderer();
marked.setOptions({ marked.setOptions({

View File

@ -575,7 +575,6 @@ function addSteeringWheelKeyboardShortcuts(
let newPos = calculatedPosList[newPosIndex]; let newPos = calculatedPosList[newPosIndex];
if (newPos.x === curPosX && newPos.y === curPosY) return; if (newPos.x === curPosX && newPos.y === curPosY) return;
// TODO add config in KeySteeringWheel.vue
if (delay) { if (delay) {
const { smoothDelay, delayStepLength } = delay; const { smoothDelay, delayStepLength } = delay;
let movePosX = curPosX; let movePosX = curPosX;

View File

@ -1,4 +1,3 @@
import { useRouter } from "vue-router";
import { LocalStore } from "../store/localStore"; import { LocalStore } from "../store/localStore";
import { NonReactiveStore } from "../store/noneReactiveStore"; import { NonReactiveStore } from "../store/noneReactiveStore";
import { useGlobalStore } from "../store/global"; import { useGlobalStore } from "../store/global";
@ -7,9 +6,7 @@ import { genClientId } from "./tools";
import { getCurrentWindow } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
export async function primaryInit() { export async function primaryInit() {
const router = useRouter();
await LocalStore.init(); await LocalStore.init();
await router.replace({ name: "mask" });
} }
let unlistenResize = () => {}; let unlistenResize = () => {};