@@ -4,7 +4,7 @@ import { PhysicalSize } from '@tauri-apps/api/dpi'
44import { Menu } from ' @tauri-apps/api/menu'
55import { sep } from ' @tauri-apps/api/path'
66import { getCurrentWebviewWindow } from ' @tauri-apps/api/webviewWindow'
7- import { exists } from ' @tauri-apps/plugin-fs'
7+ import { exists , readDir } from ' @tauri-apps/plugin-fs'
88import { useDebounceFn , useEventListener } from ' @vueuse/core'
99import { nth } from ' es-toolkit/compat'
1010import { onMounted , onUnmounted , ref , watch } from ' vue'
@@ -17,7 +17,9 @@ import { hideWindow, setAlwaysOnTop, setTaskbarVisibility, showWindow } from '@/
1717import { useCatStore } from ' @/stores/cat'
1818import { useGeneralStore } from ' @/stores/general.ts'
1919import { useModelStore } from ' @/stores/model'
20+ import { isImage } from ' @/utils/is'
2021import { join } from ' @/utils/path'
22+ import { clearObject } from ' @/utils/shared'
2123
2224const { startListening } = useDevice ()
2325const appWindow = getCurrentWebviewWindow ()
@@ -47,15 +49,32 @@ useEventListener('resize', () => {
4749})
4850
4951watch (() => modelStore .currentModel , async (model ) => {
50- handleLoad ()
51-
5252 if (! model ) return
5353
54+ handleLoad ()
55+
5456 const path = join (model .path , ' resources' , ' background.png' )
5557
5658 const existed = await exists (path )
5759
5860 backgroundImagePath .value = existed ? convertFileSrc (path ) : void 0
61+
62+ clearObject ([modelStore .supportKeys , modelStore .pressedKeys ])
63+
64+ const resourcePath = join (model .path , ' resources' )
65+ const groups = [' left-keys' , ' right-keys' ]
66+
67+ for await (const groupName of groups ) {
68+ const groupDir = join (resourcePath , groupName )
69+ const files = await readDir (groupDir ).catch (() => [])
70+ const imageFiles = files .filter (file => isImage (file .name ))
71+
72+ for (const file of imageFiles ) {
73+ const fileName = file .name .split (' .' )[0 ]
74+
75+ modelStore .supportKeys [fileName ] = join (groupDir , file .name )
76+ }
77+ }
5978}, { deep: true , immediate: true })
6079
6180watch ([() => catStore .scale , modelSize ], async () => {
0 commit comments