Skip to content

Commit a6265bb

Browse files
committed
feat(stage-tamagotchi): inlay window & spotlight position calculation
1 parent f46774c commit a6265bb

File tree

6 files changed

+83
-12
lines changed

6 files changed

+83
-12
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { dirname, join, resolve } from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
4+
import { BrowserWindow, shell } from 'electron'
5+
import { isMacOS } from 'std-env'
6+
7+
import icon from '../../../../resources/icon.png?asset'
8+
9+
import { baseUrl, load, withHashRoute } from '../../libs/electron/location'
10+
import { currentDisplayBounds, mapForBreakpoints, resolutionBreakpoints, widthFrom } from '../shared/display'
11+
import { spotlightLikeWindowConfig } from '../shared/window'
12+
13+
const __dirname = dirname(fileURLToPath(import.meta.url))
14+
15+
export async function setupInlayWindow() {
16+
const window = new BrowserWindow({
17+
title: 'Inlay',
18+
width: 450,
19+
height: 150,
20+
show: false,
21+
icon,
22+
webPreferences: {
23+
preload: join(dirname(fileURLToPath(import.meta.url)), '../preload/index.mjs'),
24+
sandbox: false,
25+
},
26+
...spotlightLikeWindowConfig(),
27+
})
28+
29+
if (isMacOS) {
30+
window.setWindowButtonVisibility(false)
31+
}
32+
33+
const displayBounds = currentDisplayBounds(window)
34+
const width = mapForBreakpoints(
35+
displayBounds.width,
36+
{
37+
'720p': widthFrom(displayBounds, { percentage: 1, max: { percentage: 0.5 } }),
38+
'1080p': widthFrom(displayBounds, { percentage: 1, max: { percentage: 0.33 } }),
39+
'2k': widthFrom(displayBounds, { percentage: 0.25, max: { actual: 710 } }),
40+
'4k': widthFrom(displayBounds, { percentage: 0.2, max: { actual: 768 } }),
41+
},
42+
{ breakpoints: resolutionBreakpoints },
43+
)
44+
const height = width / 4
45+
46+
window.setBounds({
47+
width,
48+
height: width / 4,
49+
x: displayBounds.x + (displayBounds.width - width) / 2, // Center horizontally
50+
y: mapForBreakpoints(
51+
displayBounds.height,
52+
{
53+
sm: displayBounds.height / 4 * 3 - height, // Bottom quarter, minus window height
54+
md: displayBounds.height / 5 * 4 - height, // Center vertically
55+
lg: displayBounds.height / 6 * 5 - height, // Top quarter, minus half window height
56+
},
57+
),
58+
})
59+
60+
window.on('ready-to-show', () => window.show())
61+
window.webContents.setWindowOpenHandler((details) => {
62+
shell.openExternal(details.url)
63+
return { action: 'deny' }
64+
})
65+
66+
await load(window, withHashRoute(baseUrl(resolve(__dirname, '..', '..', 'renderer')), '/inlay'))
67+
68+
return window
69+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
1111

1212
export async function setupSettingsWindow() {
1313
const window = new BrowserWindow({
14-
title: 'AIRI',
14+
title: 'Settings',
1515
width: 600.0,
1616
height: 800.0,
1717
show: false,

apps/stage-tamagotchi/src/renderer/components/Window/TitleBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const { platform } = useAppRuntime()
1313
<div
1414
bg="neutral-100 dark:neutral-900" w="100dvw"
1515
top="0"
16-
data-tauri-drag-region fixed z-100 w-full select-none py-2 pr-4
16+
fixed z-100 w-full select-none py-2 pr-4 drag-region
1717
:class="[
1818
platform === 'macos' ? 'pl-20' : 'pl-4',
1919
]"
2020
>
21-
<div data-tauri-drag-region flex>
21+
<div flex drag-region>
2222
<div
2323
bg="hover:neutral-200 hover:dark:neutral-800"
2424
transition="all duration-200 ease-in-out"
@@ -27,7 +27,7 @@ const { platform } = useAppRuntime()
2727
<div :class="icon" select-none text="neutral-400 dark:neutral-500" whitespace-nowrap />
2828
<div><span select-none whitespace-nowrap text-sm>{{ title }}</span></div>
2929
</div>
30-
<div data-tauri-drag-region w-full />
30+
<div w-full drag-region />
3131
<div
3232
bg="hover:neutral-200 hover:dark:neutral-800"
3333
transition="all duration-200 ease-in-out"

apps/stage-tamagotchi/src/renderer/pages/index.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ const modeIndicatorClass = computed(() => {
107107
>
108108
<div
109109
v-if="windowControlStore.controlMode === WindowControlMode.MOVE"
110-
class="drag-region absolute left-0 top-0 z-99 h-full w-full flex cursor-grab items-center justify-center overflow-hidden"
110+
class="absolute left-0 top-0 z-99 h-full w-full flex cursor-grab items-center justify-center overflow-hidden drag-region"
111111
>
112112
<div
113113
class="absolute h-32 w-full flex items-center justify-center overflow-hidden rounded-xl"
114114
bg="white/80 dark:neutral-950/80" backdrop-blur="md"
115115
>
116116
<div class="wall absolute top-0 h-8" />
117-
<div class="drag-region absolute left-0 top-0 h-full w-full flex animate-flash animate-duration-5s animate-count-infinite select-none items-center justify-center text-1.5rem text-primary-400 font-normal">
117+
<div class="absolute left-0 top-0 h-full w-full flex animate-flash animate-duration-5s animate-count-infinite select-none items-center justify-center text-1.5rem text-primary-400 font-normal drag-region">
118118
DRAG HERE TO MOVE
119119
</div>
120-
<div class="wall drag-region absolute bottom-0 h-8" />
120+
<div class="wall absolute bottom-0 h-8 drag-region" />
121121
</div>
122122
</div>
123123
</Transition>
@@ -139,10 +139,6 @@ const modeIndicatorClass = computed(() => {
139139
</template>
140140

141141
<style scoped>
142-
.drag-region {
143-
app-region: drag;
144-
}
145-
146142
.view {
147143
transition: opacity 0.5s ease-in-out;
148144
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div class="drag-region">
3+
<h1>Spotlight</h1>
4+
<p>This is the Spotlight page.</p>
5+
</div>
6+
</template>

apps/stage-tamagotchi/src/renderer/pages/onboarding.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function handleConfigured() {
1919

2020
<template>
2121
<div h-full w-full flex flex-col overflow-x-hidden overflow-y-hidden overscroll-none>
22-
<div bg="white dark:#181818" w="100dvw" min-h="12" data-tauri-drag-region w-full flex-shrink-0 select-none />
22+
<div bg="white dark:#181818" w="100dvw" min-h="12" w-full flex-shrink-0 select-none data-tauri-drag-region />
2323
<div w-full flex-1 overflow-y-scroll px-3>
2424
<div h-full py-3>
2525
<OnboardingScreen @skipped="handleSkipped" @configured="handleConfigured" />

0 commit comments

Comments
 (0)