fix: 修复找不到内置模型路径的问题 (#511)

This commit is contained in:
ayangweb
2025-06-17 19:35:53 +08:00
committed by GitHub
parent 7df7aad81a
commit beeecb617f
3 changed files with 31 additions and 10 deletions

View File

@@ -38,7 +38,9 @@ onMounted(async () => {
await catStore.$tauri.start()
await generalStore.$tauri.start()
await shortcutStore.$tauri.start()
catStore.visible = true
modelStore.init()
catStore.init()
restoreState()
})

View File

@@ -11,6 +11,10 @@ export const useCatStore = defineStore('cat', () => {
const scale = ref(100)
const opacity = ref(100)
const init = () => {
visible.value = true
}
return {
visible,
mirrorMode,
@@ -20,5 +24,6 @@ export const useCatStore = defineStore('cat', () => {
alwaysOnTop,
scale,
opacity,
init,
}
})

View File

@@ -1,7 +1,7 @@
import { resolveResource } from '@tauri-apps/api/path'
import { nanoid } from 'nanoid'
import { defineStore } from 'pinia'
import { onMounted, ref } from 'vue'
import { ref } from 'vue'
import { join } from '@/utils/path'
@@ -37,33 +37,47 @@ export const useModelStore = defineStore('model', () => {
const motions = ref<MotionGroup>({})
const expressions = ref<Expression[]>([])
onMounted(async () => {
const modelsPath = await resolveResource('assets/models')
const init = async () => {
const presetModelsPath = await resolveResource('assets/models')
if (models.value.length === 0) {
const modes: ModelMode[] = ['standard', 'keyboard']
for await (const mode of modes) {
const path = join(modelsPath, mode)
models.value.push({
id: nanoid(),
path,
mode,
id: nanoid(),
isPreset: true,
path: join(presetModelsPath, mode),
})
}
} else {
models.value = models.value.map((item) => {
const { isPreset, mode } = item
if (!isPreset) return item
return {
...item,
path: join(presetModelsPath, mode),
}
})
}
if (currentModel.value) return
const matched = models.value.find(item => item.id === currentModel.value?.id)
if (matched) {
return currentModel.value = matched
}
currentModel.value = models.value[0]
})
}
return {
models,
currentModel,
motions,
expressions,
init,
}
})