Skip to content

Commit c2b20f1

Browse files
UandUfindUayangweb
andauthored
feat: 新增「猫咪设置 > 模型设置 > 单键模式」配置项
* feat: 新增「猫咪设置 > 模型设置 > 单键模式」配置项 * refactor: 重构单键模式代码 --------- Co-authored-by: userName <userEmail> Co-authored-by: ayang <473033518@qq.com>
1 parent 3b53216 commit c2b20f1

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

src/components/pro-list/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { title } = defineProps<{
88

99
<template>
1010
<Flex
11-
class="mb-4"
11+
class="not-last:mb-4"
1212
gap="small"
1313
vertical
1414
>

src/composables/useDevice.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Ref } from 'vue'
22

33
import { useDebounceFn } from '@vueuse/core'
4+
import { uniq } from 'es-toolkit'
45
import { reactive, ref, watch } from 'vue'
56

67
import { LISTEN_KEY } from '../constants'
@@ -9,11 +10,9 @@ import { useTauriListen } from './useTauriListen'
910

1011
import { useCatStore } from '@/stores/cat'
1112

12-
type MouseButtonValue = 'Left' | 'Right' | 'Middle'
13-
1413
interface MouseButtonEvent {
1514
kind: 'MousePress' | 'MouseRelease'
16-
value: MouseButtonValue
15+
value: string
1716
}
1817

1918
interface MouseMoveValue {
@@ -44,7 +43,7 @@ function getSupportKeys() {
4443
const supportKeys = getSupportKeys()
4544

4645
export function useDevice() {
47-
const pressedMouses = ref<MouseButtonValue[]>([])
46+
const pressedMouses = ref<string[]>([])
4847
const mousePosition = reactive<MouseMoveValue>({ x: 0, y: 0 })
4948
const pressedKeys = ref<string[]>([])
5049
const catStore = useCatStore()
@@ -57,13 +56,19 @@ export function useDevice() {
5756
handleRelease(pressedKeys, 'CapsLock')
5857
}, 100)
5958

60-
const handlePress = <T>(array: Ref<T[]>, value?: T) => {
59+
const handlePress = (array: Ref<string[]>, value?: string) => {
6160
if (!value) return
6261

63-
array.value = [...new Set([...array.value, value])]
62+
if (catStore.singleMode) {
63+
array.value = array.value.filter((item) => {
64+
return item.endsWith('Arrow') !== value.endsWith('Arrow')
65+
})
66+
}
67+
68+
array.value = uniq(array.value.concat(value))
6469
}
6570

66-
const handleRelease = <T>(array: Ref<T[]>, value?: T) => {
71+
const handleRelease = (array: Ref<string[]>, value?: string) => {
6772
if (!value) return
6873

6974
array.value = array.value.filter(item => item !== value)

src/composables/useSharedMenu.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ export function useSharedMenu() {
116116
text: '不透明度',
117117
items: await getOpacityMenuItems(),
118118
}),
119-
CheckMenuItem.new({
120-
text: '镜像模式',
121-
checked: catStore.mirrorMode,
122-
action: () => {
123-
catStore.mirrorMode = !catStore.mirrorMode
124-
},
125-
}),
126119
])
127120
}
128121

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@ function opacityFormatter(value?: number) {
3030
</script>
3131

3232
<template>
33-
<ProList title="模式设置">
33+
<ProList title="模型设置">
3434
<ProListItem title="选择模式">
3535
<Select
3636
v-model:value="catStore.mode"
3737
:options="modeList"
38-
title="选择模式"
3938
/>
4039
</ProListItem>
40+
41+
<ProListItem title="镜像模式">
42+
<Switch v-model:checked="catStore.mirrorMode" />
43+
</ProListItem>
44+
45+
<ProListItem
46+
description="启用后,每只手只显示最后按下的一个按键"
47+
title="单键模式"
48+
>
49+
<Switch v-model:checked="catStore.singleMode" />
50+
</ProListItem>
4151
</ProList>
4252

4353
<ProList title="窗口设置">
@@ -72,9 +82,5 @@ function opacityFormatter(value?: number) {
7282
:tip-formatter="opacityFormatter"
7383
/>
7484
</ProListItem>
75-
76-
<ProListItem title="镜像模式">
77-
<Switch v-model:checked="catStore.mirrorMode" />
78-
</ProListItem>
7985
</ProList>
8086
</template>

src/pages/preference/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const menus = [
8484
v-for="(item, index) in menus"
8585
v-show="current === index"
8686
:key="item.label"
87-
class="flex-1 bg-color-8 p-4"
87+
class="flex-1 overflow-auto bg-color-8 p-4"
8888
data-tauri-drag-region
8989
>
9090
<component :is="item.component" />

src/stores/cat.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import { ref } from 'vue'
44
export type CatMode = 'standard' | 'keyboard'
55

66
export const useCatStore = defineStore('cat', () => {
7-
const mode = ref<CatMode>('standard')
87
const visible = ref(true)
8+
const mode = ref<CatMode>('standard')
9+
const mirrorMode = ref(false)
10+
const singleMode = ref(false)
911
const penetrable = ref(false)
1012
const scale = ref(100)
1113
const opacity = ref(100)
12-
const mirrorMode = ref(false)
1314

1415
return {
15-
mode,
1616
visible,
17+
mode,
18+
mirrorMode,
19+
singleMode,
1720
penetrable,
1821
scale,
1922
opacity,
20-
mirrorMode,
2123
}
2224
})

0 commit comments

Comments
 (0)