fix(desktop): configure proxy for renderer session (#11708)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { Session } from 'electron';
|
||||
|
||||
type ProxySession = Pick<Session, 'setProxy'>;
|
||||
type ProxyEnvironment = Record<string, string | undefined>;
|
||||
|
||||
export async function configureProxy(
|
||||
defaultSession: ProxySession,
|
||||
rendererSession: ProxySession,
|
||||
environment: ProxyEnvironment = process.env
|
||||
): Promise<void> {
|
||||
const httpsProxy = environment.HTTPS_PROXY || environment.https_proxy;
|
||||
const httpProxy = environment.HTTP_PROXY || environment.http_proxy;
|
||||
const proxyUrl = httpsProxy || httpProxy;
|
||||
|
||||
if (!proxyUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Main] Configuring proxy');
|
||||
const proxyConfig = {
|
||||
proxyRules: proxyUrl,
|
||||
proxyBypassRules: environment.NO_PROXY || environment.no_proxy || '',
|
||||
};
|
||||
|
||||
await Promise.all([defaultSession.setProxy(proxyConfig), rendererSession.setProxy(proxyConfig)]);
|
||||
console.log('[Main] Proxy configured successfully');
|
||||
}
|
||||
Reference in New Issue
Block a user