diff --git a/apps/stage-tamagotchi/electron.vite.config.ts b/apps/stage-tamagotchi/electron.vite.config.ts index 68b99304f..b37474c62 100644 --- a/apps/stage-tamagotchi/electron.vite.config.ts +++ b/apps/stage-tamagotchi/electron.vite.config.ts @@ -1,7 +1,4 @@ -import type { UserConfig } from 'electron-vite' - import { join, resolve } from 'node:path' -import { env } from 'node:process' import VueI18n from '@intlify/unplugin-vue-i18n/vite' import templateCompilerOptions from '@tresjs/core/template-compiler-options' @@ -17,12 +14,12 @@ import VueRouter from 'vue-router/vite' import { Download } from '@proj-airi/unplugin-fetch' import { DownloadLive2DSDK } from '@proj-airi/unplugin-live2d-sdk' -import { defineConfig, loadEnv } from 'electron-vite' +import { defineConfig } from 'electron-vite' const stageUIAssetsRoot = resolve(join(import.meta.dirname, '..', '..', 'packages', 'stage-ui', 'src', 'assets')) const sharedCacheDir = resolve(join(import.meta.dirname, '..', '..', '.cache')) -const electronConfig = { +export default defineConfig({ main: { build: { externalizeDeps: { @@ -261,13 +258,4 @@ const electronConfig = { Download('https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-B/AvatarSample_B.vrm', 'AvatarSample_B.vrm', 'vrm/models/AvatarSample-B', { parentDir: stageUIAssetsRoot, cacheDir: sharedCacheDir }), ], }, -} satisfies UserConfig - -export default defineConfig(({ mode }) => { - // Main-process code reads runtime `process.env`, while electron-vite normally - // keeps file-based variables in `import.meta.env`. Load only APP_ values as - // soon as the Electron config is evaluated; shell values take priority. - Object.assign(env, loadEnv(mode, import.meta.dirname, 'APP_')) - - return electronConfig }) diff --git a/apps/stage-tamagotchi/src/main/app/debugger.test.ts b/apps/stage-tamagotchi/src/main/app/debugger.test.ts deleted file mode 100644 index 735d39be2..000000000 --- a/apps/stage-tamagotchi/src/main/app/debugger.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { EventEmitter } from 'node:events' - -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' - -import { openDebugger } from './debugger' - -const electronMocks = vi.hoisted(() => ({ - appendSwitch: vi.fn(), - openExternal: vi.fn(), -})) - -const httpMocks = vi.hoisted(() => ({ - get: vi.fn(), -})) - -vi.mock('electron', () => ({ - app: { - commandLine: { - appendSwitch: electronMocks.appendSwitch, - }, - }, - shell: { - openExternal: electronMocks.openExternal, - }, -})) - -vi.mock('node:http', () => ({ - default: { - get: httpMocks.get, - }, -})) - -describe('openDebugger', () => { - beforeEach(() => { - vi.clearAllMocks() - process.env.APP_REMOTE_DEBUG = 'true' - process.env.APP_REMOTE_DEBUG_PORT = '9250' - }) - - afterEach(() => { - delete process.env.APP_REMOTE_DEBUG - delete process.env.APP_REMOTE_DEBUG_PORT - delete process.env.APP_REMOTE_DEBUG_NO_OPEN - }) - - function emitDebuggerTarget() { - const response = new EventEmitter() - const request = new EventEmitter() - - httpMocks.get.mockImplementation((_url, handleResponse) => { - handleResponse(response) - return request - }) - - openDebugger() - - response.emit('data', JSON.stringify([{ - webSocketDebuggerUrl: 'ws://localhost:9250/devtools/page/renderer', - }])) - response.emit('end') - } - - it('opens the remote inspector unless the developer opts out', () => { - emitDebuggerTarget() - - expect(electronMocks.openExternal).toHaveBeenCalledWith( - 'http://localhost:9250/devtools/inspector.html?ws=localhost:9250/devtools/page/renderer', - ) - }) - - it('does not open the remote inspector when APP_REMOTE_DEBUG_NO_OPEN is enabled', () => { - process.env.APP_REMOTE_DEBUG_NO_OPEN = 'true' - - emitDebuggerTarget() - - // ROOT CAUSE: - // - // The existing opt-out flag was only set by automation; the application - // never read it, so every development launch still opened the browser. - // - // Reading the flag keeps CDP available and logged while leaving the - // developer's browser alone. - expect(electronMocks.openExternal).not.toHaveBeenCalled() - }) -})