Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Oct 21, 2023
1 parent 85479f7 commit 9ff68ab
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/network-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const networkSetup = '/usr/sbin/networksetup';

export function isProxyAvaliable() {
const proxy = process.env.HTTP_PROXY;
return proxy && proxy.split(':').length > 2;
return proxy && Array.isArray(proxy.split(':')) && proxy.split(':').length > 2;
}

function getProxySetting() {
Expand Down Expand Up @@ -58,23 +58,20 @@ function setupWinProxy(proxy: any) {
} = proxy;
const prefix =
'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ';

const opts = { async: false};
shell.exec(`${prefix} MigrateProxy /t REG_DWORD /d 1 /f`, opts)
shell.exec(`${prefix} ProxyEnable /t REG_DWORD /d 1 /f`, opts)
shell.exec(`${prefix} ProxyHttp1.1 /t REG_DWORD /d 1 /f`, opts)
shell.exec(`${prefix} EnableLegacyAutoProxyFeatures /t REG_DWORD /d 1 /f`, opts)
shell.exec(`${prefix} ProxyServer /t REG_SZ /d "${proxyHost}:${proxyPort}" /f`, opts)
shell.exec(`${prefix} ProxyOverride /t REG_SZ /d "localhost;127.0.0.1" /f`, opts)
// registry changes won't take affect right away unless we refresh wininet

// Registry changes won't take effect immediately; we need to refresh wininet.
const refreshScript = path.join(__dirname, '../', 'scripts', 'win-refresh-wininet.ps1');
shell.exec(`powershell.exe -ExecutionPolicy Bypass ${refreshScript}`, opts);
}

export function setupProxy() {
if (!isProxyAvaliable()) {
return;
}
const proxy = getProxySetting();
if (!proxy) {
return;
Expand Down

0 comments on commit 9ff68ab

Please sign in to comment.