mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-11 02:28:30 +08:00
feat: add proxy settings to Settings dialog (Desktop only) (#537)
* feat: add proxy settings to Settings dialog (Desktop only) Fixes #535 - Desktop app now respects HTTP/HTTPS proxy configuration. - Add proxy-manager.ts to handle proxy config storage (JSON file in userData) - Load proxy settings on app startup before Next.js server starts - Add IPC handlers for get-proxy and set-proxy - Add proxy settings UI in Settings dialog (Electron only) - Add translations for en/zh/ja * fix: improve proxy settings reliability and simplify UI - Fix server restart race condition (wait for process exit before starting new server) - Add URL validation (must include http:// or https:// prefix) - Enable Node.js built-in proxy support (NODE_USE_ENV_PROXY=1) - Remove "Proxy Exceptions" field (unnecessary for this app) - Add debug logging for proxy env vars * refactor: remove duplicate ProxyConfig interface, import from electron.d.ts
This commit is contained in:
@@ -11,6 +11,12 @@ import {
|
||||
updatePreset,
|
||||
} from "./config-manager"
|
||||
import { restartNextServer } from "./next-server"
|
||||
import {
|
||||
applyProxyToEnv,
|
||||
getProxyConfig,
|
||||
type ProxyConfig,
|
||||
saveProxyConfig,
|
||||
} from "./proxy-manager"
|
||||
|
||||
/**
|
||||
* Allowed configuration keys for presets
|
||||
@@ -209,4 +215,40 @@ export function registerIpcHandlers(): void {
|
||||
return setCurrentPreset(id)
|
||||
},
|
||||
)
|
||||
|
||||
// ==================== Proxy Settings ====================
|
||||
|
||||
ipcMain.handle("get-proxy", () => {
|
||||
return getProxyConfig()
|
||||
})
|
||||
|
||||
ipcMain.handle("set-proxy", async (_event, config: ProxyConfig) => {
|
||||
try {
|
||||
// Save config to file
|
||||
saveProxyConfig(config)
|
||||
|
||||
// Apply to current process environment
|
||||
applyProxyToEnv()
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development"
|
||||
|
||||
if (isDev) {
|
||||
// In development, env vars are already applied
|
||||
// Next.js dev server may need manual restart
|
||||
return { success: true, devMode: true }
|
||||
}
|
||||
|
||||
// Production: restart Next.js server to pick up new env vars
|
||||
await restartNextServer()
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Failed to apply proxy settings",
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user