-
-
Notifications
You must be signed in to change notification settings - Fork 63
feat: respect system proxy settings on Windows platform #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Zagrios
merged 12 commits into
Zagrios:master
from
GoldJohnKing:feat/702-respect-system-proxy-windows
Dec 26, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
46db881
feat: respect system proxy settings on Windows platform
GoldJohnKing 675ae26
Merge remote-tracking branch 'origin/master' into feat/702-respect-sy…
GoldJohnKing 2c0b33f
refactor: using regedit-rs instead of winreg
GoldJohnKing 57b7ee0
Remove winreg package, clean up package-lock.json
GoldJohnKing 9e9fc14
optimize as suggested
GoldJohnKing 68c174c
Add toggle-able system proxy setting
GoldJohnKing a12cefe
Merge branch 'master' into feat/702-respect-system-proxy-windows
GoldJohnKing aed34e6
Merge branch 'master' into feat/702-respect-system-proxy-windows
GoldJohnKing 4eb8c06
add multilingual translation for system proxy, fix mis-spelled words
GoldJohnKing ce89532
move proxy-helper init entry to main.ts for earlier init
GoldJohnKing 3c1faf8
switching proxy enable/disable does not require app restart anymore
GoldJohnKing d09fbb0
remove redundant strings entries of system proxy module
GoldJohnKing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import log from 'electron-log'; | ||
import { RegDwordValue, RegSzValue } from "regedit-rs" | ||
import { execOnOs } from "../helpers/env.helpers"; | ||
import { bootstrap } from 'global-agent'; | ||
import { StaticConfigurationService } from "../services/static-configuration.service"; | ||
|
||
const staticConfig = StaticConfigurationService.getInstance(); | ||
|
||
const { list } = (execOnOs({ win32: () => require("regedit-rs") }, true) ?? {}) as typeof import("regedit-rs"); | ||
|
||
async function isProxyEnabled(): Promise<boolean>{ | ||
const res = await list("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); | ||
const key = res["HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"]; | ||
if(!key.exists){ throw new Error("Key \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" not exist"); } | ||
const registryValue = key.values.ProxyEnable as RegDwordValue; | ||
if(!registryValue){ throw new Error("Value \"ProxyEnable\" not exist"); } | ||
return (1 === registryValue.value); | ||
} | ||
|
||
async function getProxyServer(): Promise<string>{ | ||
const res = await list("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); | ||
const key = res["HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"]; | ||
if(!key.exists){ throw new Error("Key \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" not exist"); } | ||
const registryValue = key.values.ProxyServer as RegSzValue; | ||
if(!registryValue){ throw new Error("Value \"ProxyServer\" not exist"); } | ||
return registryValue.value; | ||
} | ||
|
||
async function getProxyOverride(): Promise<string>{ | ||
const res = await list("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); | ||
const key = res["HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"]; | ||
if(!key.exists){ throw new Error("Key \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" not exist"); } | ||
const registryValue = key.values.ProxyOverride as RegSzValue; | ||
if(!registryValue){ throw new Error("Value \"ProxyOverride\" not exist"); } | ||
return registryValue.value; | ||
} | ||
|
||
async function enableWindowsProxy(enable: boolean): Promise<void> { | ||
if (!(await isProxyEnabled().catch(err => log.error(err)))) { | ||
log.info("enableWindowsProxy: System proxy not detected"); | ||
return; | ||
} | ||
|
||
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") { | ||
enableWindowsProxy(staticConfig.get("use-system-proxy")); | ||
|
||
staticConfig.$watch("use-system-proxy").subscribe((useSystemProxy) => { | ||
enableWindowsProxy(useSystemProxy); | ||
|
||
log.info(`configureProxy: UseSystemProxy is set to ${useSystemProxy}`); | ||
}); | ||
} else { | ||
log.info("configureProxy: Unsupported platform"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.