diff --git a/src/main/helpers/proxy.helpers.ts b/src/main/helpers/proxy.helpers.ts index ba4ec320..71f9a366 100644 --- a/src/main/helpers/proxy.helpers.ts +++ b/src/main/helpers/proxy.helpers.ts @@ -35,41 +35,47 @@ async function getProxyOverride(): Promise{ return registryValue.value; } -async function configureWindowsProxy() : Promise { - if (await isProxyEnabled().catch(err => log.error(err))) { - const httpProxyUrl = `http://${await getProxyServer().catch(err => log.error(err))}` - process.env.GLOBAL_AGENT_HTTP_PROXY = httpProxyUrl; - process.env.GLOBAL_AGENT_HTTPS_PROXY = httpProxyUrl; - - process.env.GLOBAL_AGENT_NO_PROXY = `${await getProxyOverride().catch(err => log.error(err))}`; - - log.info(`configureWindowsProxy: Using system proxy: ${process.env.GLOBAL_AGENT_HTTP_PROXY}`); - - bootstrap(); +async function enableWindowsProxy(enable: boolean): Promise { + if (!(await isProxyEnabled().catch(err => log.error(err)))) { + log.info("enableWindowsProxy: System proxy not detected"); + return; } - else { - log.info(`configureWindowsProxy: System proxy not detected`); + + let { GLOBAL_AGENT: globalProxyAgent } = global as any; + if (!globalProxyAgent) { // If this is undefined, call bootstrap to set it up + if (!bootstrap()) { + log.error("enableWindowsProxy: Could not setup proxy stuff"); + return; + } + globalProxyAgent = (global as any).GLOBAL_AGENT; + } + + if (enable) { + const httpProxyUrl = `http://${await getProxyServer().catch(err => log.error(err))}` + globalProxyAgent.HTTP_PROXY = httpProxyUrl; + globalProxyAgent.HTTPS_PROXY = httpProxyUrl; + globalProxyAgent.NO_PROXY = `${await getProxyOverride().catch(err => log.error(err))}`; + + log.info(`enableWindowsProxy: Using system proxy: ${httpProxyUrl}`); + } else { + delete globalProxyAgent.HTTP_PROXY; + delete globalProxyAgent.HTTPS_PROXY; + delete globalProxyAgent.NO_PROXY; + + log.info("enableWindowsProxy: proxy disabled"); } } export function configureProxy() { if (process.platform === "win32") { - const useSystemProxy = staticConfig.get("use-system-proxy"); - - if (useSystemProxy === true) { - configureWindowsProxy(); - } - - log.info(`configureProxy: UseSystemProxy is set to ${useSystemProxy}`); + enableWindowsProxy(staticConfig.get("use-system-proxy")); staticConfig.$watch("use-system-proxy").subscribe((useSystemProxy) => { - if (useSystemProxy === true) { - configureWindowsProxy(); - } + enableWindowsProxy(useSystemProxy); log.info(`configureProxy: UseSystemProxy is set to ${useSystemProxy}`); }); } else { - log.info('configureProxy: Unsupported platform'); + log.info("configureProxy: Unsupported platform"); } } diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index cd26de6d..19530fb4 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -617,20 +617,6 @@ function AdvancedSettings() { return; } - if(!newUseSystemProxy){ - const res = await modal.openModal(BasicModal, { data: { - title: "pages.settings.advanced.use-system-proxy.modal.title", - body: "pages.settings.advanced.use-system-proxy.modal.body", - image: BeatConflict, - buttons: [ - { id: "cancel", text: "misc.cancel", type: "cancel" }, - { id: "confirm", text: "pages.settings.advanced.use-system-proxy.modal.confirm-btn", type: "error", onClick: () => true } - ] - }}); - - if(res.exitCode !== ModalExitCode.COMPLETED || res.data !== "confirm"){ return; } - } - const { error } = await tryit(() => staticConfig.set("use-system-proxy", newUseSystemProxy)); if(error){ @@ -639,15 +625,6 @@ function AdvancedSettings() { } setUseSystemProxy(() => newUseSystemProxy); - - if(!progressBar.require()){ - return; - } - - if (!newUseSystemProxy) { - await lastValueFrom(ipc.sendV2("restart-app")); - } - } const advancedItems: Item[] = [{