Skip to content

Commit beeecb6

Browse files
authored
fix: 修复找不到内置模型路径的问题 (#511)
1 parent 7df7aad commit beeecb6

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ onMounted(async () => {
3838
await catStore.$tauri.start()
3939
await generalStore.$tauri.start()
4040
await shortcutStore.$tauri.start()
41-
catStore.visible = true
41+
42+
modelStore.init()
43+
catStore.init()
4244
4345
restoreState()
4446
})

src/stores/cat.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const useCatStore = defineStore('cat', () => {
1111
const scale = ref(100)
1212
const opacity = ref(100)
1313

14+
const init = () => {
15+
visible.value = true
16+
}
17+
1418
return {
1519
visible,
1620
mirrorMode,
@@ -20,5 +24,6 @@ export const useCatStore = defineStore('cat', () => {
2024
alwaysOnTop,
2125
scale,
2226
opacity,
27+
init,
2328
}
2429
})

src/stores/model.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolveResource } from '@tauri-apps/api/path'
22
import { nanoid } from 'nanoid'
33
import { defineStore } from 'pinia'
4-
import { onMounted, ref } from 'vue'
4+
import { ref } from 'vue'
55

66
import { join } from '@/utils/path'
77

@@ -37,33 +37,47 @@ export const useModelStore = defineStore('model', () => {
3737
const motions = ref<MotionGroup>({})
3838
const expressions = ref<Expression[]>([])
3939

40-
onMounted(async () => {
41-
const modelsPath = await resolveResource('assets/models')
40+
const init = async () => {
41+
const presetModelsPath = await resolveResource('assets/models')
4242

4343
if (models.value.length === 0) {
4444
const modes: ModelMode[] = ['standard', 'keyboard']
4545

4646
for await (const mode of modes) {
47-
const path = join(modelsPath, mode)
48-
4947
models.value.push({
50-
id: nanoid(),
51-
path,
5248
mode,
49+
id: nanoid(),
5350
isPreset: true,
51+
path: join(presetModelsPath, mode),
5452
})
5553
}
54+
} else {
55+
models.value = models.value.map((item) => {
56+
const { isPreset, mode } = item
57+
58+
if (!isPreset) return item
59+
60+
return {
61+
...item,
62+
path: join(presetModelsPath, mode),
63+
}
64+
})
5665
}
5766

58-
if (currentModel.value) return
67+
const matched = models.value.find(item => item.id === currentModel.value?.id)
68+
69+
if (matched) {
70+
return currentModel.value = matched
71+
}
5972

6073
currentModel.value = models.value[0]
61-
})
74+
}
6275

6376
return {
6477
models,
6578
currentModel,
6679
motions,
6780
expressions,
81+
init,
6882
}
6983
})

0 commit comments

Comments
 (0)