From f1f3b2862c6183322f7d0368f8865c373f2a1c85 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Fri, 26 Apr 2024 23:07:26 +0800 Subject: [PATCH] feat(KeyBoard+Mask+hotkey): load local key mapping config --- src/App.vue | 44 ++++- src/components/Mask.vue | 30 ++- src/components/keyboard/KeyBoard.vue | 10 +- src/components/keyboard/KeySetting.vue | 80 ++++++-- src/hotkey.ts | 52 ++++- src/keyMappingConfig.ts | 100 ++++++++++ src/store/global.ts | 258 +------------------------ 7 files changed, 287 insertions(+), 287 deletions(-) create mode 100644 src/keyMappingConfig.ts diff --git a/src/App.vue b/src/App.vue index 59efc40..9d9f2f7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,6 +7,45 @@ import { NMessageProvider, NDialogProvider, } from "naive-ui"; +import { Store } from "@tauri-apps/plugin-store"; +import { getCurrent } from "@tauri-apps/api/window"; +import { KeyMappingConfig } from "./keyMappingConfig"; +import { onMounted } from "vue"; +import { useGlobalStore } from "./store/global"; + +const store = useGlobalStore(); + +onMounted(async () => { + // loading keyMappingConfigList from local store + const localStore = new Store("store.bin"); + let keyMappingConfigList: KeyMappingConfig[] | null = await localStore.get( + "keyMappingConfigList" + ); + if (keyMappingConfigList === null || keyMappingConfigList.length === 0) { + keyMappingConfigList = [ + { + relativeSize: await calMaskSize(), + title: "空白方案", + list: [], + }, + ]; + } + + store.keyMappingConfigList = keyMappingConfigList; +}); + +async function calMaskSize() { + const appWindow = getCurrent(); + const ml = 70; + const mt = 30; + let size = (await appWindow.outerSize()).toLogical( + await appWindow.scaleFactor() + ); + return { + w: Math.round(size.width) - ml, + h: Math.round(size.height) - mt, + }; +}