Skip to content

Commit a703d0a

Browse files
authored
feat: 新增「猫咪设置 > 模型设置 > 动作与表情」配置项 (#908)
1 parent 48e0021 commit a703d0a

9 files changed

Lines changed: 40 additions & 11 deletions

File tree

src/composables/useKeyPress.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ import {
66
register,
77
unregister,
88
} from '@tauri-apps/plugin-global-shortcut'
9-
import { ref, watch } from 'vue'
9+
import { onUnmounted, ref, watch } from 'vue'
1010

1111
export function useKeyPress(shortcut: Ref<string | undefined, string>, callback: ShortcutHandler) {
12-
// This is primarily to prevent errors during hot reloading in the development environment.
1312
const oldShortcut = ref(shortcut.value)
1413

15-
watch(shortcut, async (value) => {
16-
if (oldShortcut.value) {
17-
const registered = await isRegistered(oldShortcut.value)
14+
async function unbind() {
15+
if (!oldShortcut.value) return
16+
17+
const registered = await isRegistered(oldShortcut.value)
18+
19+
if (!registered) return
1820

19-
if (registered) {
20-
await unregister(oldShortcut.value)
21-
}
22-
}
21+
return unregister(oldShortcut.value)
22+
}
23+
24+
watch(shortcut, async (value) => {
25+
await unbind()
2326

2427
if (!value) return
2528

@@ -31,4 +34,6 @@ export function useKeyPress(shortcut: Ref<string | undefined, string>, callback:
3134

3235
oldShortcut.value = value
3336
}, { immediate: true })
37+
38+
onUnmounted(unbind)
3439
}

src/locales/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"windowRadius": "Window Radius",
2323
"opacity": "Opacity",
2424
"motionSound": "Motion Sound",
25+
"behavior": "Motions and Expressions",
2526
"autoReleaseDelay": "Auto Release Delay",
2627
"hideOnHover": "Hide on Hover"
2728
},
@@ -30,6 +31,7 @@
3031
"singleMode": "When enabled, only the last pressed key is displayed for each hand.",
3132
"mouseMirror": "When enabled, the mouse will mirror the hand movement.",
3233
"motionSound": "When enabled, the model will play corresponding sound effects when performing actions (if they exist).",
34+
"behavior": "When enabled, motions and expressions can be configured and triggered.",
3335
"passThrough": "When enabled, clicks pass through the window without affecting it.",
3436
"alwaysOnTop": "When enabled, the window stays above all other windows.",
3537
"keepInScreen": "When enabled, the window automatically stays within the screen boundaries.",

src/locales/pt-BR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"windowRadius": "Raio da Janela",
2323
"opacity": "Opacidade",
2424
"motionSound": "Som de Ação",
25+
"behavior": "Movimentos e Expressões",
2526
"autoReleaseDelay": "Atraso de Liberação Automática",
2627
"hideOnHover": "Ocultar ao Passar o Mouse"
2728
},
@@ -30,6 +31,7 @@
3031
"singleMode": "Quando ativado, apenas a última tecla pressionada em cada mão é exibida (evita mostrar múltiplas mãos ao pressionar várias teclas ao mesmo tempo).",
3132
"mouseMirror": "Quando ativado, o mouse espelhará o movimento da mão.",
3233
"motionSound": "Quando ativado, o modelo reproduzirá efeitos sonoros correspondentes ao executar ações (se existirem).",
34+
"behavior": "Quando ativado, movimentos e expressões podem ser configurados e acionados.",
3335
"passThrough": "Quando ativado, a janela não afetará operações em outros aplicativos.",
3436
"alwaysOnTop": "Quando ativado, a janela sempre ficará acima de outros aplicativos.",
3537
"keepInScreen": "Quando ativado, a janela permanece automaticamente dentro dos limites da tela.",

src/locales/vi-VN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"windowRadius": "Độ bo tròn cửa sổ",
2323
"opacity": "Độ mờ",
2424
"motionSound": "Âm thanh hành động",
25+
"behavior": "Hành động và Biểu cảm",
2526
"autoReleaseDelay": "Độ trễ tự động nhả phím",
2627
"hideOnHover": "Ẩn khi di chuột"
2728
},
@@ -30,6 +31,7 @@
3031
"singleMode": "Khi bật, mỗi tay mèo chỉ hiển thị phím vừa nhấn cuối cùng (tránh hiện nhiều tay khi nhấn nhiều phím cùng lúc).",
3132
"mouseMirror": "Khi bật, chuột của mô hình sẽ phản chiếu theo chuyển động chuột thực tế.",
3233
"motionSound": "Khi bật, mô hình sẽ phát các âm thanh tương ứng khi thực hiện hành động (nếu tồn tại).",
34+
"behavior": "Khi bật, các hành động và biểu cảm có thể được cấu hình và kích hoạt.",
3335
"passThrough": "Bật để cửa sổ không ảnh hưởng đến thao tác trên ứng dụng khác.",
3436
"alwaysOnTop": "Bật để cửa sổ luôn nằm trên ứng dụng khác.",
3537
"keepInScreen": "Khi bật, cửa sổ sẽ tự động giữ trong ranh giới màn hình.",

src/locales/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"windowRadius": "窗口圆角",
2323
"opacity": "不透明度",
2424
"motionSound": "动作音效",
25+
"behavior": "动作与表情",
2526
"autoReleaseDelay": "按键自动释放延迟",
2627
"hideOnHover": "鼠标移入隐藏"
2728
},
@@ -30,6 +31,7 @@
3031
"singleMode": "启用后,每只手只显示最后按下的一个按键。",
3132
"mouseMirror": "启用后,鼠标将镜像跟随手部移动。",
3233
"motionSound": "启用后,模型执行动作时会播放对应音效(如果存在)。",
34+
"behavior": "启用后,可以配置和触发模型的动作与表情。",
3335
"passThrough": "启用后,窗口不影响对其他应用程序的操作。",
3436
"alwaysOnTop": "启用后,窗口始终显示在其他应用程序上方。",
3537
"keepInScreen": "启用后,窗口会自动调整位置,防止超出屏幕边界。",

src/locales/zh-TW.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"windowRadius": "視窗圓角",
2323
"opacity": "不透明度",
2424
"motionSound": "動作音效",
25+
"behavior": "動作與表情",
2526
"autoReleaseDelay": "按鍵自動釋放延遲",
2627
"hideOnHover": "滑鼠游標移入隱藏"
2728
},
@@ -30,6 +31,7 @@
3031
"singleMode": "啟用後,每隻手只顯示最後按下的一個按鍵。",
3132
"mouseMirror": "啟用後,滑鼠游標將鏡像跟隨手部移動。",
3233
"motionSound": "啟用後,模型執行動作時會播放對應音效(如果存在)。",
34+
"behavior": "啟用後,可以配置和觸發模型的動作與表情。",
3335
"passThrough": "啟用後,視窗不影響對其他應用程式的操作。",
3436
"alwaysOnTop": "啟用後,視窗始終顯示在其他應用程式上方。",
3537
"keepInScreen": "啟用後,視窗會自動調整位置,防止超出螢幕邊界。",

src/pages/preference/components/cat/index.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ const catStore = useCatStore()
3939
<Switch v-model:checked="catStore.model.motionSound" />
4040
</ProListItem>
4141

42+
<ProListItem
43+
:description="$t('pages.preference.cat.hints.behavior')"
44+
:title="$t('pages.preference.cat.labels.behavior')"
45+
>
46+
<Switch v-model:checked="catStore.model.behavior" />
47+
</ProListItem>
48+
4249
<ProListItem
4350
v-if="isWindows"
4451
:description="$t('pages.preference.cat.hints.autoReleaseDelay')"

src/pages/preference/components/model/index.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import BehaviorModal from './components/behavior-modal/index.vue'
1515
import FloatMenu from './components/float-menu/index.vue'
1616
import Upload from './components/upload/index.vue'
1717
18+
import { useCatStore } from '@/stores/cat'
1819
import { useModelStore } from '@/stores/model'
1920
import { join } from '@/utils/path'
2021
22+
const catStore = useCatStore()
2123
const modelStore = useModelStore()
2224
const firstItemRef = ref<HTMLElement>()
2325
const { height } = useElementSize(firstItemRef)
@@ -89,7 +91,7 @@ async function handleDelete(item: Model) {
8991
/>
9092

9193
<i
92-
v-if="modelStore.currentModel?.id === item.id"
94+
v-if="catStore.model.behavior && modelStore.currentModel?.id === item.id"
9395
class="i-lucide:smile"
9496
@click.stop="openBehaviorModal = true"
9597
/>
@@ -119,5 +121,8 @@ async function handleDelete(item: Model) {
119121

120122
<FloatMenu />
121123

122-
<BehaviorModal v-model="openBehaviorModal" />
124+
<BehaviorModal
125+
v-if="catStore.model.behavior"
126+
v-model="openBehaviorModal"
127+
/>
123128
</template>

src/stores/cat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface CatStore {
77
single: boolean
88
mouseMirror: boolean
99
motionSound: boolean
10+
behavior: boolean
1011
autoReleaseDelay: number
1112
}
1213
window: {
@@ -53,6 +54,7 @@ export const useCatStore = defineStore('cat', () => {
5354
single: false,
5455
mouseMirror: false,
5556
motionSound: true,
57+
behavior: true,
5658
autoReleaseDelay: 3,
5759
})
5860

0 commit comments

Comments
 (0)