Skip to content

Commit 3203381

Browse files
committed
feat(stage-tamagotchi): follow cursor
1 parent 69c4df9 commit 3203381

File tree

9 files changed

+67
-14
lines changed

9 files changed

+67
-14
lines changed

apps/stage-tamagotchi/src/main/libs/event-loop/loop.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ export function useLoop(fn: () => Promise<void> | void, options?: { interval?: n
22
let timer: NodeJS.Timeout | null = null
33
let shouldRun = options?.autoStart ?? true
44

5-
const loopIteration = () => {
5+
const loopIteration = async () => {
66
if (!shouldRun) {
77
return
88
}
99

10-
const res = fn()
11-
if (res instanceof Promise) {
12-
res.finally(() => {
13-
timer = setTimeout(loopIteration, options?.interval ?? 1000 / 60) // Default to ~60 FPS
14-
})
10+
try {
11+
await fn()
1512
}
16-
else {
17-
timer = setTimeout(loopIteration, options?.interval ?? 1000 / 60)
13+
finally {
14+
timer = setTimeout(loopIteration, options?.interval ?? 1000 / 60) // Default to ~60 FPS
1815
}
1916
}
2017

apps/stage-tamagotchi/src/main/windows/settings/rpc/index.electron.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { createContext } from '@unbird/eventa/adapters/electron/main'
55
import { ipcMain } from 'electron'
66

77
import { electronOpenSettingsDevtools } from '../../../../shared/eventa'
8+
import { createFadeOnHoverService } from '../../../services/fade-on-hover'
89

910
export async function setupSettingsWindowInvokes(params: { settingsWindow: BrowserWindow }) {
1011
const { context } = createContext(ipcMain, params.settingsWindow)
1112

13+
createFadeOnHoverService(context)
1214
defineInvokeHandler(context, electronOpenSettingsDevtools, async () => params.settingsWindow.webContents.openDevTools({ mode: 'detach' }))
1315
}

apps/stage-tamagotchi/src/renderer/pages/devtools/use-magic-keys.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const Key = defineComponent({
136136
<slot />
137137
</template>
138138

139-
<!-- <route lang="yaml">
139+
<route lang="yaml">
140140
meta:
141141
layout: settings
142-
</route> -->
142+
</route>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import { useWindowMouse } from '../../stores/window-mouse'
3+
4+
const { x, y } = useWindowMouse()
5+
</script>
6+
7+
<template>
8+
<div class="flex flex-col md:flex-row">
9+
<div>
10+
<div class="flex justify-center gap-3">
11+
{{ x }}, {{ y }}
12+
</div>
13+
</div>
14+
</div>
15+
</template>
16+
17+
<route lang="yaml">
18+
meta:
19+
layout: settings
20+
</route>

apps/stage-tamagotchi/src/renderer/pages/settings/system/developer.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const menu = computed(() => [
1818
icon: 'i-solar:sledgehammer-bold-duotone',
1919
to: '/devtools/use-magic-keys',
2020
},
21+
{
22+
title: t('tamagotchi.settings.pages.system.developer.sections.section.use-window-mouse.title'),
23+
description: t('tamagotchi.settings.pages.system.developer.sections.section.use-window-mouse.description'),
24+
icon: 'i-solar:sledgehammer-bold-duotone',
25+
to: '/devtools/use-window-mouse',
26+
},
2127
])
2228
2329
const { context } = createContext(window.electron.ipcRenderer)

apps/stage-tamagotchi/src/renderer/stores/features/ai/models/whisper.worker.ts

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineInvoke } from '@unbird/eventa'
2+
import { createContext } from '@unbird/eventa/adapters/electron/renderer'
3+
import { ref } from 'vue'
4+
5+
import { electronCursorPoint, electronStartTrackingCursorPoint } from '../../shared/eventa'
6+
7+
export function useWindowMouse(options?: { x: number, y: number }) {
8+
const context = ref(createContext(window.electron.ipcRenderer).context)
9+
const centerPosition = ref<{ x: number, y: number }>({ x: 0, y: 0 })
10+
const positionX = ref(options?.x ?? 0)
11+
const positionY = ref(options?.y ?? 0)
12+
13+
context.value!.on(electronCursorPoint, (event) => {
14+
positionX.value = event.body?.x ?? centerPosition.value.x
15+
positionY.value = event.body?.y ?? centerPosition.value.y
16+
})
17+
18+
defineInvoke(context.value!, electronStartTrackingCursorPoint)()
19+
20+
return {
21+
x: positionX,
22+
y: positionY,
23+
}
24+
}

apps/stage-tamagotchi/src/renderer/stores/window.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import { useWindowSize } from '@vueuse/core'
22
import { defineStore } from 'pinia'
33
import { computed, ref } from 'vue'
44

5-
// import { useTauriWindowClickThrough } from '../composables/tauri-window-pass-through-on-hover'
65
import { useWindowControlStore } from './window-controls'
6+
import { useWindowMouse } from './window-mouse'
77

88
export const useWindowStore = defineStore('tamagotchi-window', () => {
99
const windowControlStore = useWindowControlStore()
1010

1111
const { width, height } = useWindowSize()
1212
const centerPos = computed(() => ({ x: width.value / 2, y: height.value / 2 }))
13-
// const { live2dLookAtX, live2dLookAtY, isCursorInside } = useTauriWindowClickThrough(centerPos)
14-
const live2dLookAtX = ref(0)
15-
const live2dLookAtY = ref(0)
13+
const { x: live2dLookAtX, y: live2dLookAtY } = useWindowMouse(centerPos.value)
1614
const isCursorInside = ref(false)
1715
const shouldHideView = computed(() => isCursorInside.value && !windowControlStore.isControlActive && windowControlStore.isIgnoringMouseEvent)
1816

packages/i18n/src/locales/en/tamagotchi/settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ pages:
2121
toggle-ignore-mouse-event:
2222
label: Toggle Ignore Mouse Event
2323
press-keys: Press Keys...
24+
developer:
25+
sections:
26+
section:
27+
use-window-mouse:
28+
title: useWindowMouse
29+
description: Test the Electron window cursor position

0 commit comments

Comments
 (0)