From 7c28122540168e37bbf15f2806378c0769fcdd88 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Thu, 23 Oct 2025 22:16:06 +0800 Subject: [PATCH] fix(stage-tamagotchi): max listener exceeded warning, set to 100 before improving eventa --- apps/stage-tamagotchi/src/main/index.ts | 7 ++++++- apps/stage-tamagotchi/src/main/windows/caption/index.ts | 8 +++++++- .../src/main/windows/main/rpc/index.electron.ts | 5 +++++ .../src/main/windows/settings/rpc/index.electron.ts | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/stage-tamagotchi/src/main/index.ts b/apps/stage-tamagotchi/src/main/index.ts index 10b9c3994..18cb30d51 100644 --- a/apps/stage-tamagotchi/src/main/index.ts +++ b/apps/stage-tamagotchi/src/main/index.ts @@ -7,7 +7,7 @@ import { platform } from 'node:process' import { electronApp, optimizer } from '@electron-toolkit/utils' import { Format, LogLevel, setGlobalFormat, setGlobalLogLevel, useLogg } from '@guiiai/logg' import { createLoggLogger, injecta } from '@proj-airi/injecta' -import { app, Menu, nativeImage, Tray } from 'electron' +import { app, ipcMain, Menu, nativeImage, Tray } from 'electron' import { noop, once } from 'es-toolkit' import { isLinux, isMacOS } from 'std-env' @@ -23,6 +23,11 @@ import { setupMainWindow } from './windows/main' import { setupSettingsWindowReusableFunc } from './windows/settings' import { toggleWindowShow } from './windows/shared/window' +// TODO: once we refactored eventa to support window-namespaced contexts, +// we can remove the setMaxListeners call below since eventa will be able to dispatch and +// manage events within eventa's context system. +ipcMain.setMaxListeners(100) + setElectronMainDirname(__dirname) setGlobalFormat(Format.Pretty) setGlobalLogLevel(LogLevel.Log) diff --git a/apps/stage-tamagotchi/src/main/windows/caption/index.ts b/apps/stage-tamagotchi/src/main/windows/caption/index.ts index 8822cc02f..552c0727a 100644 --- a/apps/stage-tamagotchi/src/main/windows/caption/index.ts +++ b/apps/stage-tamagotchi/src/main/windows/caption/index.ts @@ -217,7 +217,7 @@ export function setupCaptionWindowManager(params: { mainWindow: BrowserWindow }) lastAppliedTy = ty // Animate towards target at throttled cadence for visible easing settleTo(tx, ty) - }, 1000 / 30) + }, 1000 / 60) const settleDebounced = debounce(() => { settleTo(lastTx, lastTy) @@ -246,6 +246,11 @@ export function setupCaptionWindowManager(params: { mainWindow: BrowserWindow }) let eventaContext: ReturnType['context'] | undefined const reusable = createReusableWindow(async () => { + // TODO: once we refactored eventa to support window-namespaced contexts, + // we can remove the setMaxListeners call below since eventa will be able to dispatch and + // manage events within eventa's context system. + ipcMain.setMaxListeners(100) + const window = createCaptionWindow() const { context } = createContext(ipcMain, window) eventaContext = context @@ -274,6 +279,7 @@ export function setupCaptionWindowManager(params: { mainWindow: BrowserWindow }) } updateConfig(config) } + window.on('resize', persistBounds) window.on('move', persistBounds) diff --git a/apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts b/apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts index d0f64974b..982e11cc5 100644 --- a/apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts +++ b/apps/stage-tamagotchi/src/main/windows/main/rpc/index.electron.ts @@ -9,6 +9,11 @@ import { createScreenService, createWindowService } from '../../../services/elec import { toggleWindowShow } from '../../shared' export function setupMainWindowElectronInvokes(params: { window: BrowserWindow, settingsWindow: () => Promise }) { + // TODO: once we refactored eventa to support window-namespaced contexts, + // we can remove the setMaxListeners call below since eventa will be able to dispatch and + // manage events within eventa's context system. + ipcMain.setMaxListeners(100) + const { context } = createContext(ipcMain, params.window) createScreenService({ context, window: params.window }) diff --git a/apps/stage-tamagotchi/src/main/windows/settings/rpc/index.electron.ts b/apps/stage-tamagotchi/src/main/windows/settings/rpc/index.electron.ts index f1389d6a2..2ea7a69ab 100644 --- a/apps/stage-tamagotchi/src/main/windows/settings/rpc/index.electron.ts +++ b/apps/stage-tamagotchi/src/main/windows/settings/rpc/index.electron.ts @@ -8,6 +8,11 @@ import { electronOpenSettingsDevtools } from '../../../../shared/eventa' import { createScreenService, createWindowService } from '../../../services/electron' export async function setupSettingsWindowInvokes(params: { settingsWindow: BrowserWindow }) { + // TODO: once we refactored eventa to support window-namespaced contexts, + // we can remove the setMaxListeners call below since eventa will be able to dispatch and + // manage events within eventa's context system. + ipcMain.setMaxListeners(0) + const { context } = createContext(ipcMain, params.settingsWindow) createScreenService({ context, window: params.settingsWindow })