Skip to content

Commit d7e4d09

Browse files
committed
feat(stage-tamagotchi): debugger for inlay window, supported to setVibrancy & setBackgroundMaterial
1 parent 0f3be91 commit d7e4d09

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

apps/stage-tamagotchi/src/main/services/electron/window.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ export function createWindowService(params: { context: ReturnType<typeof createC
4040
params.window.setIgnoreMouseEvents(...opts)
4141
}
4242
})
43+
44+
defineInvokeHandler(params.context, electron.window.setVibrancy, (vibrancy, options) => {
45+
if (params.window.webContents.id === options?.raw.ipcMainEvent.sender.id) {
46+
params.window.setVibrancy(vibrancy[0])
47+
}
48+
})
49+
50+
defineInvokeHandler(params.context, electron.window.setBackgroundMaterial, (backgroundMaterial, options) => {
51+
if (params.window.webContents.id === options?.raw.ipcMainEvent.sender.id) {
52+
params.window.setBackgroundMaterial(backgroundMaterial[0])
53+
}
54+
})
4355
}

apps/stage-tamagotchi/src/main/windows/inlay/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import icon from '../../../../resources/icon.png?asset'
88
import { baseUrl, getElectronMainDirname, load, withHashRoute } from '../../libs/electron/location'
99
import { currentDisplayBounds, mapForBreakpoints, resolutionBreakpoints, widthFrom } from '../shared/display'
1010
import { spotlightLikeWindowConfig } from '../shared/window'
11+
import { setupInlayWindowInvokes } from './rpc/index.electron'
1112

1213
export async function setupInlayWindow() {
1314
const window = new BrowserWindow({
@@ -62,5 +63,7 @@ export async function setupInlayWindow() {
6263

6364
await load(window, withHashRoute(baseUrl(resolve(getElectronMainDirname(), '..', 'renderer')), '/inlay'))
6465

66+
setupInlayWindowInvokes({ inlayWindow: window })
67+
6568
return window
6669
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { BrowserWindow } from 'electron'
2+
3+
import { createContext } from '@moeru/eventa/adapters/electron/main'
4+
import { ipcMain } from 'electron'
5+
6+
import { createWindowService } from '../../../services/electron'
7+
8+
export async function setupInlayWindowInvokes(params: {
9+
inlayWindow: BrowserWindow
10+
}) {
11+
// TODO: once we refactored eventa to support window-namespaced contexts,
12+
// we can remove the setMaxListeners call below since eventa will be able to dispatch and
13+
// manage events within eventa's context system.
14+
ipcMain.setMaxListeners(0)
15+
16+
const { context } = createContext(ipcMain, params.inlayWindow)
17+
18+
createWindowService({ context, window: params.inlayWindow })
19+
}

apps/stage-tamagotchi/src/main/windows/shared/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function transparentWindowConfig(): BrowserWindowConstructorOptions {
2929

3030
export function blurryWindowConfig(): BrowserWindowConstructorOptions {
3131
return {
32-
vibrancy: 'under-window',
32+
vibrancy: 'hud',
3333
backgroundMaterial: 'acrylic',
3434
}
3535
}
Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,85 @@
1+
<script setup lang="ts">
2+
import type { BackgroundMaterialType, VibrancyType } from '../../../shared/electron/window'
3+
4+
import { FieldSelect } from '@proj-airi/ui'
5+
import { ref, watch } from 'vue'
6+
7+
import { electron } from '../../../shared/electron'
8+
import { useElectronEventaInvoke } from '../../composables/electron-vueuse'
9+
10+
const setVibrancy = useElectronEventaInvoke(electron.window.setVibrancy)
11+
const setBackgroundMaterial = useElectronEventaInvoke(electron.window.setBackgroundMaterial)
12+
13+
const vibrancy = ref<NonNullable<VibrancyType>>()
14+
const backgroundMaterial = ref<NonNullable<BackgroundMaterialType>>()
15+
16+
watch(
17+
vibrancy,
18+
(newVibrancy) => {
19+
setVibrancy([newVibrancy ?? null])
20+
},
21+
)
22+
23+
watch(
24+
backgroundMaterial,
25+
(newBackgroundMaterial) => {
26+
if (!newBackgroundMaterial)
27+
return
28+
29+
setBackgroundMaterial([newBackgroundMaterial])
30+
},
31+
)
32+
</script>
33+
134
<template>
2-
<div class="drag-region">
3-
<h1>Spotlight</h1>
4-
<p>This is the Spotlight page.</p>
35+
<div class="p-4">
36+
<div class="drag-region" />
37+
38+
<div class="py-4">
39+
<h1>Spotlight</h1>
40+
<p>This is the Spotlight page.</p>
41+
</div>
42+
43+
<div class="space-y-2">
44+
<FieldSelect
45+
v-model="vibrancy"
46+
label="Vibrancy"
47+
description="Set the vibrancy effect of the window."
48+
:options="[
49+
{ label: 'titlebar', value: 'titlebar' },
50+
{ label: 'selection', value: 'selection' },
51+
{ label: 'menu', value: 'menu' },
52+
{ label: 'popover', value: 'popover' },
53+
{ label: 'sidebar', value: 'sidebar' },
54+
{ label: 'header', value: 'header' },
55+
{ label: 'sheet', value: 'sheet' },
56+
{ label: 'window', value: 'window' },
57+
{ label: 'hud', value: 'hud' },
58+
{ label: 'fullscreen-ui', value: 'fullscreen-ui' },
59+
{ label: 'tooltip', value: 'tooltip' },
60+
{ label: 'content', value: 'content' },
61+
{ label: 'under-window', value: 'under-window' },
62+
{ label: 'under-page', value: 'under-page' },
63+
]"
64+
/>
65+
66+
<FieldSelect
67+
v-model="backgroundMaterial"
68+
label="Background Material"
69+
description="Set the background material of the window."
70+
:options="[
71+
{ label: 'auto', value: 'auto' },
72+
{ label: 'none', value: 'none' },
73+
{ label: 'mica', value: 'mica' },
74+
{ label: 'acrylic', value: 'acrylic' },
75+
{ label: 'tabbed', value: 'tabbed' },
76+
]"
77+
/>
78+
</div>
579
</div>
680
</template>
81+
82+
<route lang="yaml">
83+
meta:
84+
layout: plain
85+
</route>

apps/stage-tamagotchi/src/shared/electron/window.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export const startLoopGetBounds = defineInvokeEventa('eventa:event:electron:wind
77

88
const getBounds = defineInvokeEventa<ReturnType<BrowserWindow['getBounds']>>('eventa:invoke:electron:window:get-bounds')
99
const setIgnoreMouseEvents = defineInvokeEventa<void, [boolean, { forward: boolean }]>('eventa:invoke:electron:window:set-ignore-mouse-events')
10+
const setVibrancy = defineInvokeEventa<void, Parameters<BrowserWindow['setVibrancy']>>('eventa:invoke:electron:window:set-vibrancy')
11+
const setBackgroundMaterial = defineInvokeEventa<void, Parameters<BrowserWindow['setBackgroundMaterial']>>('eventa:invoke:electron:window:set-background-material')
12+
13+
export type VibrancyType = Parameters<BrowserWindow['setVibrancy']>[0]
14+
export type BackgroundMaterialType = Parameters<BrowserWindow['setBackgroundMaterial']>[0]
1015

1116
export const window = {
1217
getBounds,
1318
setIgnoreMouseEvents,
19+
setVibrancy,
20+
setBackgroundMaterial,
1421
}

0 commit comments

Comments
 (0)