fix(desktop): respect proxy environment (#25846)

This commit is contained in:
Luke Parker 2026-05-05 20:34:28 +10:00 committed by GitHub
parent bb9b81aa37
commit 465c83cf82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import { randomUUID } from "node:crypto"
import { EventEmitter } from "node:events"
import { existsSync } from "node:fs"
import * as http from "node:http"
import { createServer } from "node:net"
import { homedir } from "node:os"
import { join } from "node:path"
@ -77,6 +78,7 @@ setupApp()
function setupApp() {
ensureLoopbackNoProxy()
useEnvProxy()
app.commandLine.appendSwitch("proxy-bypass-list", "<-loopback>")
if (!app.isPackaged) app.commandLine.appendSwitch("remote-debugging-port", "9222")
@ -133,6 +135,15 @@ function useSystemCertificates() {
}
}
function useEnvProxy() {
try {
// Electron 41.2 runs Node 24.14.1; latest @types/node@24 is 24.12.2.
;(http as any).setGlobalProxyFromEnv()
} catch (error) {
logger.warn("failed to load proxy environment", error)
}
}
function emitDeepLinks(urls: string[]) {
if (urls.length === 0) return
pendingDeepLinks.push(...urls)
@ -189,7 +200,10 @@ async function initialize() {
}
logger.log("spawning sidecar", { url })
const { listener, health } = await spawnLocalServer(hostname, port, password)
const { listener, health } = await spawnLocalServer(hostname, port, password, () => {
ensureLoopbackNoProxy()
useEnvProxy()
})
server = listener
serverReady.resolve({
url,

View file

@ -30,8 +30,9 @@ export function setWslConfig(config: WslConfig) {
getStore().set(WSL_ENABLED_KEY, config.enabled)
}
export async function spawnLocalServer(hostname: string, port: number, password: string) {
export async function spawnLocalServer(hostname: string, port: number, password: string, configureEnv?: () => void) {
prepareServerEnv(password)
configureEnv?.()
const { Log, Server } = await import("virtual:opencode-server")
await Log.init({ level: "WARN" })
const listener = await Server.listen({