Skip to content

Commit 8408ffc

Browse files
committed
feat(stage-tamagotchi): settings page
1 parent c07f2af commit 8408ffc

File tree

5 files changed

+49
-16
lines changed

5 files changed

+49
-16
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import macOSTrayIcon from '../../resources/tray-icon-macos.png?asset'
1414

1515
import { openDebugger, setupDebugger } from './app/debugger'
1616
import { emitAppBeforeQuit, emitAppReady, emitAppWindowAllClosed, onAppBeforeQuit } from './libs/bootkit/lifecycle'
17-
import { setup } from './windows/main'
18-
import { useWebInvokes } from './windows/main/eventa/index.web'
17+
import { setupMainWindow } from './windows/main'
18+
import { setupSettingsWindow } from './windows/settings'
1919
import { toggleWindowShow } from './windows/shared/window'
2020

2121
setGlobalFormat(Format.Pretty)
2222
setGlobalLogLevel(LogLevel.Log)
2323
setupDebugger()
2424

25-
const log = useLogg('main')
25+
const log = useLogg('main').useGlobalConfig()
2626

2727
app.dock?.setIcon(icon)
2828
electronApp.setAppUserModelId('ai.moeru.airi')
@@ -40,14 +40,7 @@ function setupTray(): void {
4040
const contextMenu = Menu.buildFromTemplate([
4141
{ label: 'Show Window', click: () => toggleWindowShow(mainWindow) },
4242
{ type: 'separator' },
43-
{
44-
label: 'Settings',
45-
click: () => {
46-
toggleWindowShow(mainWindow)
47-
const web = useWebInvokes()
48-
web.openSettings()
49-
},
50-
},
43+
{ label: 'Settings', click: () => setupSettingsWindow() },
5144
{ type: 'separator' },
5245
{ label: 'Quit', click: () => app.quit() },
5346
])
@@ -98,7 +91,7 @@ async function setupProjectAIRIServerRuntime() {
9891
app.whenReady().then(async () => {
9992
await setupProjectAIRIServerRuntime()
10093

101-
mainWindow = setup()
94+
mainWindow = setupMainWindow()
10295
setupTray()
10396

10497
// Lifecycle

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import icon from '../../../../resources/icon.png?asset'
1313

1414
import { transparentWindowConfig } from '../shared'
1515
import { createConfig } from '../shared/persistence'
16-
import { setupAppInvokeHandlers } from './eventa/index.electron'
17-
import { setupWebInvokes } from './eventa/index.web'
16+
import { setupAppInvokeHandlers } from './rpc/index.electron'
1817

1918
interface AppConfig {
2019
windows?: Array<Pick<BrowserWindowConstructorOptions, 'title' | 'x' | 'y' | 'width' | 'height'> & { tag: string }>
2120
}
2221

23-
export function setup() {
22+
export function setupMainWindow() {
2423
const {
2524
setup: setupConfig,
2625
get: getConfig,
@@ -102,7 +101,6 @@ export function setup() {
102101
}
103102

104103
setupAppInvokeHandlers(window)
105-
setupWebInvokes(window)
106104

107105
return window
108106
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { dirname, join } from 'node:path'
2+
import { env } from 'node:process'
3+
import { fileURLToPath } from 'node:url'
4+
5+
import { is } from '@electron-toolkit/utils'
6+
import { BrowserWindow, shell } from 'electron'
7+
8+
import icon from '../../../../resources/icon.png?asset'
9+
10+
import { setupWebInvokes } from './rpc/index.web'
11+
12+
export async function setupSettingsWindow() {
13+
const window = new BrowserWindow({
14+
title: 'AIRI',
15+
width: 600.0,
16+
height: 800.0,
17+
show: false,
18+
icon,
19+
webPreferences: {
20+
preload: join(dirname(fileURLToPath(import.meta.url)), '../preload/index.mjs'),
21+
sandbox: false,
22+
},
23+
})
24+
25+
window.on('ready-to-show', () => window.show())
26+
window.webContents.setWindowOpenHandler((details) => {
27+
shell.openExternal(details.url)
28+
return { action: 'deny' }
29+
})
30+
31+
if (is.dev && env.ELECTRON_RENDERER_URL) {
32+
await window.loadURL(`${env.ELECTRON_RENDERER_URL}/#/settings`)
33+
}
34+
else {
35+
await window.loadFile(join(__dirname, '../renderer/index.html/#/settings'))
36+
}
37+
38+
// Setup
39+
setupWebInvokes(window)
40+
41+
return window
42+
}

0 commit comments

Comments
 (0)