From 8408ffca4c682c1fc4ea1431ec6d746b5e7cfb0a Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Tue, 7 Oct 2025 17:41:42 +0800 Subject: [PATCH] feat(stage-tamagotchi): settings page --- apps/stage-tamagotchi/src/main/index.ts | 17 +++----- .../src/main/windows/main/index.ts | 6 +-- .../main/{eventa => rpc}/index.electron.ts | 0 .../src/main/windows/settings/index.ts | 42 +++++++++++++++++++ .../eventa => settings/rpc}/index.web.ts | 0 5 files changed, 49 insertions(+), 16 deletions(-) rename apps/stage-tamagotchi/src/main/windows/main/{eventa => rpc}/index.electron.ts (100%) rename apps/stage-tamagotchi/src/main/windows/{main/eventa => settings/rpc}/index.web.ts (100%) diff --git a/apps/stage-tamagotchi/src/main/index.ts b/apps/stage-tamagotchi/src/main/index.ts index 9acb2fd15..0934a546d 100644 --- a/apps/stage-tamagotchi/src/main/index.ts +++ b/apps/stage-tamagotchi/src/main/index.ts @@ -14,15 +14,15 @@ import macOSTrayIcon from '../../resources/tray-icon-macos.png?asset' import { openDebugger, setupDebugger } from './app/debugger' import { emitAppBeforeQuit, emitAppReady, emitAppWindowAllClosed, onAppBeforeQuit } from './libs/bootkit/lifecycle' -import { setup } from './windows/main' -import { useWebInvokes } from './windows/main/eventa/index.web' +import { setupMainWindow } from './windows/main' +import { setupSettingsWindow } from './windows/settings' import { toggleWindowShow } from './windows/shared/window' setGlobalFormat(Format.Pretty) setGlobalLogLevel(LogLevel.Log) setupDebugger() -const log = useLogg('main') +const log = useLogg('main').useGlobalConfig() app.dock?.setIcon(icon) electronApp.setAppUserModelId('ai.moeru.airi') @@ -40,14 +40,7 @@ function setupTray(): void { const contextMenu = Menu.buildFromTemplate([ { label: 'Show Window', click: () => toggleWindowShow(mainWindow) }, { type: 'separator' }, - { - label: 'Settings', - click: () => { - toggleWindowShow(mainWindow) - const web = useWebInvokes() - web.openSettings() - }, - }, + { label: 'Settings', click: () => setupSettingsWindow() }, { type: 'separator' }, { label: 'Quit', click: () => app.quit() }, ]) @@ -98,7 +91,7 @@ async function setupProjectAIRIServerRuntime() { app.whenReady().then(async () => { await setupProjectAIRIServerRuntime() - mainWindow = setup() + mainWindow = setupMainWindow() setupTray() // Lifecycle diff --git a/apps/stage-tamagotchi/src/main/windows/main/index.ts b/apps/stage-tamagotchi/src/main/windows/main/index.ts index 7039b6443..f215a74a9 100644 --- a/apps/stage-tamagotchi/src/main/windows/main/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/main/index.ts @@ -13,14 +13,13 @@ import icon from '../../../../resources/icon.png?asset' import { transparentWindowConfig } from '../shared' import { createConfig } from '../shared/persistence' -import { setupAppInvokeHandlers } from './eventa/index.electron' -import { setupWebInvokes } from './eventa/index.web' +import { setupAppInvokeHandlers } from './rpc/index.electron' interface AppConfig { windows?: Array & { tag: string }> } -export function setup() { +export function setupMainWindow() { const { setup: setupConfig, get: getConfig, @@ -102,7 +101,6 @@ export function setup() { } setupAppInvokeHandlers(window) - setupWebInvokes(window) return window } diff --git a/apps/stage-tamagotchi/src/main/windows/main/eventa/index.electron.ts b/apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts similarity index 100% rename from apps/stage-tamagotchi/src/main/windows/main/eventa/index.electron.ts rename to apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts diff --git a/apps/stage-tamagotchi/src/main/windows/settings/index.ts b/apps/stage-tamagotchi/src/main/windows/settings/index.ts index e69de29bb..4f58ba8ff 100644 --- a/apps/stage-tamagotchi/src/main/windows/settings/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/settings/index.ts @@ -0,0 +1,42 @@ +import { dirname, join } from 'node:path' +import { env } from 'node:process' +import { fileURLToPath } from 'node:url' + +import { is } from '@electron-toolkit/utils' +import { BrowserWindow, shell } from 'electron' + +import icon from '../../../../resources/icon.png?asset' + +import { setupWebInvokes } from './rpc/index.web' + +export async function setupSettingsWindow() { + const window = new BrowserWindow({ + title: 'AIRI', + width: 600.0, + height: 800.0, + show: false, + icon, + webPreferences: { + preload: join(dirname(fileURLToPath(import.meta.url)), '../preload/index.mjs'), + sandbox: false, + }, + }) + + window.on('ready-to-show', () => window.show()) + window.webContents.setWindowOpenHandler((details) => { + shell.openExternal(details.url) + return { action: 'deny' } + }) + + if (is.dev && env.ELECTRON_RENDERER_URL) { + await window.loadURL(`${env.ELECTRON_RENDERER_URL}/#/settings`) + } + else { + await window.loadFile(join(__dirname, '../renderer/index.html/#/settings')) + } + + // Setup + setupWebInvokes(window) + + return window +} diff --git a/apps/stage-tamagotchi/src/main/windows/main/eventa/index.web.ts b/apps/stage-tamagotchi/src/main/windows/settings/rpc/index.web.ts similarity index 100% rename from apps/stage-tamagotchi/src/main/windows/main/eventa/index.web.ts rename to apps/stage-tamagotchi/src/main/windows/settings/rpc/index.web.ts