feat(stage-tamagotchi): settings page

This commit is contained in:
Neko Ayaka
2025-10-07 17:41:42 +08:00
parent c07f2afe98
commit 8408ffca4c
5 changed files with 49 additions and 16 deletions
+5 -12
View File
@@ -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
@@ -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<Pick<BrowserWindowConstructorOptions, 'title' | 'x' | 'y' | 'width' | 'height'> & { 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
}
@@ -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
}