diff --git a/src/App.vue b/src/App.vue index a90bea08..1ef49e4e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,6 +18,7 @@ import { getAntdLocale } from './locales/index.ts' import { hideWindow, showWindow } from './plugins/window' import { useAppStore } from './stores/app' import { useCatStore } from './stores/cat' +import { useCounterStore } from './stores/counter.ts' import { useGeneralStore } from './stores/general' import { useModelStore } from './stores/model' import { useShortcutStore } from './stores/shortcut.ts' @@ -25,6 +26,7 @@ import { useShortcutStore } from './stores/shortcut.ts' const { generateColorVars } = useThemeVars() const appStore = useAppStore() const modelStore = useModelStore() +const counterStore = useCounterStore() const catStore = useCatStore() const generalStore = useGeneralStore() const shortcutStore = useShortcutStore() @@ -46,6 +48,8 @@ onMounted(async () => { await generalStore.init() await shortcutStore.$tauri.start() await restoreState() + await counterStore.init() + await counterStore.$tauri.start() }) watch(() => generalStore.appearance.language, (value) => { diff --git a/src/composables/useModel.ts b/src/composables/useModel.ts index 7248096d..0cafe416 100644 --- a/src/composables/useModel.ts +++ b/src/composables/useModel.ts @@ -11,6 +11,7 @@ import { ref } from 'vue' import live2d from '../utils/live2d' import { useCatStore } from '@/stores/cat' +import { useCounterStore } from '@/stores/counter' import { useModelStore } from '@/stores/model' import { getCursorMonitor } from '@/utils/monitor' @@ -25,6 +26,7 @@ export function useModel() { const modelStore = useModelStore() const catStore = useCatStore() const modelSize = ref() + const counterStore = useCounterStore() async function handleLoad() { try { @@ -72,6 +74,8 @@ export function useModel() { } const handlePress = (key: string) => { + counterStore.addKeyPressCount() + const path = modelStore.supportKeys[key] if (!path) return @@ -105,6 +109,7 @@ export function useModel() { const id = key === 'Left' ? 'ParamMouseLeftDown' : 'ParamMouseRightDown' live2d.setParameterValue(id, pressed) + counterStore.addMouseClickCount(pressed) } async function handleMouseMove(cursorPoint: PhysicalPosition) { diff --git a/src/pages/main/index.vue b/src/pages/main/index.vue index 5cf11db1..396e1d03 100644 --- a/src/pages/main/index.vue +++ b/src/pages/main/index.vue @@ -8,6 +8,7 @@ import { exists, readDir } from '@tauri-apps/plugin-fs' import { useDebounceFn, useEventListener } from '@vueuse/core' import { round } from 'es-toolkit' import { nth } from 'es-toolkit/compat' +import { storeToRefs } from 'pinia' import { onMounted, onUnmounted, ref, watch } from 'vue' import { useDevice } from '@/composables/useDevice' @@ -17,6 +18,7 @@ import { useSharedMenu } from '@/composables/useSharedMenu' import { useWindowPosition } from '@/composables/useWindowPosition' import { hideWindow, setAlwaysOnTop, setTaskbarVisibility, showWindow } from '@/plugins/window' import { useCatStore } from '@/stores/cat' +import { useCounterStore } from '@/stores/counter' import { useGeneralStore } from '@/stores/general.ts' import { useModelStore } from '@/stores/model' import { isImage } from '@/utils/is' @@ -34,6 +36,7 @@ const resizing = ref(false) const backgroundImagePath = ref() const { stickActive } = useGamepad() const { isMounted, setWindowPosition } = useWindowPosition() +const { totalCount } = storeToRefs(useCounterStore()) onMounted(startListening) @@ -177,6 +180,10 @@ function handleMouseMove(event: MouseEvent) { :src="convertFileSrc(path)" > +
+ {{ totalCount }} +
+
{ + const keyPressCount = ref(0) + const mouseClickCount = ref(0) + const totalCount = computed(() => keyPressCount.value + mouseClickCount.value) + + function addKeyPressCount() { + keyPressCount.value++ + } + + function addMouseClickCount(pressed = true) { + if (pressed) { + mouseClickCount.value++ + } + } + + async function getMouseClickCount() { + mouseClickCount.value = 0 + } + + async function getKeyPressCount() { + keyPressCount.value = 0 + } + + const init = async () => { + Promise.all([ + getKeyPressCount(), + getMouseClickCount(), + ]) + } + + return { + init, + totalCount, + keyPressCount, + mouseClickCount, + addKeyPressCount, + addMouseClickCount, + } +})