@@ -14,6 +14,7 @@ import { writeFile, readFile } from 'fs/promises';
1414import { safeHandle , setMainWindowId } from './ipcUtils.js' ;
1515import { logger } from './logger.js' ;
1616import { registerAIHandlers } from './ai/index.js' ;
17+ import { loadPersistedGatewayUrl , setRuntimeGatewayUrl } from './ai/utils.js' ;
1718import { initAutoUpdater , checkForUpdate , downloadUpdate , installUpdate , destroyAutoUpdater , setAutoCheckEnabled } from './updater.js' ;
1819import { createMainWindow , saveCloseChoice } from './windowManager.js' ;
1920import { destroyTray } from './trayManager.js' ;
@@ -99,8 +100,8 @@ if (!gotTheLock) {
99100 // 开发环境:允许 unsafe-inline/unsafe-eval(Vite HMR 需要)
100101 // 生产环境:禁止 unsafe-eval,保留 unsafe-inline(Tailwind 运行时需要)
101102 const csp = isDev
102- ? "default-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*; connect-src 'self' http://localhost:* ws://localhost:* https://*.supabase.co wss://*.supabase.co; img-src 'self' data: blob: https://*.supabase.co; font-src 'self' data:;"
103- : "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://*.supabase.co; font-src 'self' data:; connect-src 'self' https://*.supabase.co wss://*.supabase.co; frame-ancestors 'none';" ;
103+ ? "default-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*; connect-src 'self' http://localhost:* ws://localhost:* https://*.supabase.co wss://*.supabase.co https://entropydecrease.com wss://entropydecrease.com ; img-src 'self' data: blob: https://*.supabase.co; font-src 'self' data:;"
104+ : "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://*.supabase.co; font-src 'self' data:; connect-src 'self' https://*.supabase.co wss://*.supabase.co https://entropydecrease.com wss://entropydecrease.com ; frame-ancestors 'none';" ;
104105
105106 callback ( {
106107 responseHeaders : {
@@ -115,6 +116,8 @@ if (!gotTheLock) {
115116 logger . error ( '[SEC] Failed to inject CSP policy' , err ) ;
116117 }
117118
119+ // 加载持久化的 AI 网关地址(在注册 handler 之前,确保 handler 可用正确的 URL)
120+ await loadPersistedGatewayUrl ( ) ;
118121 registerAIHandlers ( ) ;
119122 registerCaptureHandlers ( ) ;
120123
@@ -130,6 +133,12 @@ if (!gotTheLock) {
130133 // 隐藏默认 Electron 菜单栏
131134 Menu . setApplicationMenu ( null ) ;
132135
136+ // AI 网关地址同步(渲染进程 → 主进程)
137+ safeHandle ( 'ai:set-gateway-url' , async ( _event , url : string ) => {
138+ await setRuntimeGatewayUrl ( url ) ;
139+ return { success : true } ;
140+ } ) ;
141+
133142 // 通用 IPC handlers
134143 safeHandle ( 'get-app-version' , async ( ) => {
135144 return app . getVersion ( ) ;
0 commit comments