From b7477cb64636b44cb4f097c7c8323f39c4cac209 Mon Sep 17 00:00:00 2001 From: yushen Date: Sat, 14 Feb 2026 07:30:42 +0800 Subject: [PATCH] feat(desktop): bridge MAIN_VITE_API_URL to process.env for packaged builds In packaged Electron builds, @multica/core is externalized and .env files are excluded. Bridge import.meta.env.MAIN_VITE_API_URL (injected at build time by electron-vite) to process.env.MULTICA_API_URL so that getApiBaseUrl() reads the correct value in staging/test environments. Co-Authored-By: Claude Opus 4.6 --- apps/desktop/src/main/electron-env.d.ts | 1 + apps/desktop/src/main/index.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/apps/desktop/src/main/electron-env.d.ts b/apps/desktop/src/main/electron-env.d.ts index 58860c2b..da3774b4 100644 --- a/apps/desktop/src/main/electron-env.d.ts +++ b/apps/desktop/src/main/electron-env.d.ts @@ -5,6 +5,7 @@ interface ImportMetaEnv { readonly MAIN_VITE_GATEWAY_URL: string readonly MAIN_VITE_WEB_URL: string + readonly MAIN_VITE_API_URL?: string } interface ImportMeta { diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index f0780a5f..07e362a1 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -44,6 +44,13 @@ process.stderr?.on?.('error', (err: NodeJS.ErrnoException) => { throw err }) +// Bridge Vite build-time env to process.env for externalized @multica/core +// In dev mode, electron-vite already loads .env into process.env; +// In packaged builds, only import.meta.env has the value (injected at build time). +if (import.meta.env.MAIN_VITE_API_URL) { + process.env.MULTICA_API_URL ??= import.meta.env.MAIN_VITE_API_URL +} + import { app, BrowserWindow, shell, ipcMain } from 'electron' import { fileURLToPath } from 'node:url' import path from 'node:path'