mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
feat: respect system proxy settings on Windows platform
This commit is contained in:
Generated
+30
-34
@@ -29,6 +29,7 @@
|
||||
"format-duration": "^3.0.2",
|
||||
"framer-motion": "^11.2.6",
|
||||
"fs-extra": "^11.2.0",
|
||||
"global-agent": "^3.0.0",
|
||||
"got": "^14.4.4",
|
||||
"history": "^5.3.0",
|
||||
"is-elevated": "^4.0.0",
|
||||
@@ -60,6 +61,7 @@
|
||||
"to-ico": "^1.1.5",
|
||||
"use-double-click": "^1.0.5",
|
||||
"use-fit-text": "^2.4.0",
|
||||
"winreg": "^1.2.5",
|
||||
"yauzl": "^3.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -74,6 +76,7 @@
|
||||
"@types/color": "^3.0.3",
|
||||
"@types/crypto-js": "^4.2.1",
|
||||
"@types/dateformat": "^5.0.0",
|
||||
"@types/global-agent": "^2.1.3",
|
||||
"@types/got": "^9.6.12",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/node": "22.8.6",
|
||||
@@ -92,6 +95,7 @@
|
||||
"@types/use-double-click": "^1.0.4",
|
||||
"@types/webpack-bundle-analyzer": "^4.4.2",
|
||||
"@types/webpack-env": "^1.18.0",
|
||||
"@types/winreg": "^1.2.36",
|
||||
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
||||
"@typescript-eslint/parser": "^6.20.0",
|
||||
"autoprefixer": "^10.4.17",
|
||||
@@ -6158,6 +6162,13 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/global-agent": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/global-agent/-/global-agent-2.1.3.tgz",
|
||||
"integrity": "sha512-rGtZZcgZcKWuKNTkGBGsqyOQ7Nn2MjXh4+xeZbf+5b5KMUx8H1rTqLRackxos7pUlreszbYjQcop5JvqCnZlLw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/got": {
|
||||
"version": "9.6.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/got/-/got-9.6.12.tgz",
|
||||
@@ -6553,6 +6564,13 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/winreg": {
|
||||
"version": "1.2.36",
|
||||
"resolved": "https://registry.npmjs.org/@types/winreg/-/winreg-1.2.36.tgz",
|
||||
"integrity": "sha512-DtafHy5A8hbaosXrbr7YdjQZaqVewXmiasRS5J4tYMzt3s1gkh40ixpxgVFfKiQ0JIYetTJABat47v9cpr/sQg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.5.10",
|
||||
"dev": true,
|
||||
@@ -8437,9 +8455,7 @@
|
||||
},
|
||||
"node_modules/boolean": {
|
||||
"version": "3.2.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
@@ -10345,7 +10361,6 @@
|
||||
},
|
||||
"node_modules/define-data-property": {
|
||||
"version": "1.1.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.1",
|
||||
@@ -10366,7 +10381,6 @@
|
||||
},
|
||||
"node_modules/define-properties": {
|
||||
"version": "1.2.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"define-data-property": "^1.0.1",
|
||||
@@ -10435,7 +10449,6 @@
|
||||
},
|
||||
"node_modules/detect-node": {
|
||||
"version": "2.1.0",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/detect-node-es": {
|
||||
@@ -11364,9 +11377,7 @@
|
||||
},
|
||||
"node_modules/es6-error": {
|
||||
"version": "4.1.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/es6-promise": {
|
||||
"version": "3.3.1",
|
||||
@@ -13131,7 +13142,6 @@
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.2.2",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2",
|
||||
@@ -13250,9 +13260,9 @@
|
||||
},
|
||||
"node_modules/global-agent": {
|
||||
"version": "3.0.0",
|
||||
"dev": true,
|
||||
"resolved": "https://registry.npmjs.org/global-agent/-/global-agent-3.0.0.tgz",
|
||||
"integrity": "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==",
|
||||
"license": "BSD-3-Clause",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"boolean": "^3.0.1",
|
||||
"es6-error": "^4.1.1",
|
||||
@@ -13267,9 +13277,7 @@
|
||||
},
|
||||
"node_modules/global-agent/node_modules/serialize-error": {
|
||||
"version": "7.0.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"type-fest": "^0.13.1"
|
||||
},
|
||||
@@ -13282,9 +13290,7 @@
|
||||
},
|
||||
"node_modules/global-agent/node_modules/type-fest": {
|
||||
"version": "0.13.1",
|
||||
"dev": true,
|
||||
"license": "(MIT OR CC0-1.0)",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
@@ -13319,7 +13325,6 @@
|
||||
},
|
||||
"node_modules/globalthis": {
|
||||
"version": "1.0.3",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"define-properties": "^1.1.3"
|
||||
@@ -13352,7 +13357,6 @@
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.1.3"
|
||||
@@ -13478,7 +13482,6 @@
|
||||
},
|
||||
"node_modules/has-property-descriptors": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.2"
|
||||
@@ -13489,7 +13492,6 @@
|
||||
},
|
||||
"node_modules/has-proto": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -13500,7 +13502,6 @@
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.0.3",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -16703,9 +16704,7 @@
|
||||
},
|
||||
"node_modules/matcher": {
|
||||
"version": "3.0.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^4.0.0"
|
||||
},
|
||||
@@ -16715,9 +16714,7 @@
|
||||
},
|
||||
"node_modules/matcher/node_modules/escape-string-regexp": {
|
||||
"version": "4.0.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
@@ -17355,7 +17352,6 @@
|
||||
},
|
||||
"node_modules/object-keys": {
|
||||
"version": "1.1.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -19620,9 +19616,7 @@
|
||||
},
|
||||
"node_modules/roarr": {
|
||||
"version": "2.15.4",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"boolean": "^3.0.1",
|
||||
"detect-node": "^2.0.4",
|
||||
@@ -19842,9 +19836,7 @@
|
||||
},
|
||||
"node_modules/semver-compare": {
|
||||
"version": "1.0.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "0.18.0",
|
||||
@@ -20304,9 +20296,7 @@
|
||||
},
|
||||
"node_modules/sprintf-js": {
|
||||
"version": "1.1.2",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"optional": true
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/sshpk": {
|
||||
"version": "1.17.0",
|
||||
@@ -22501,6 +22491,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/winreg": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.5.tgz",
|
||||
"integrity": "sha512-uf7tHf+tw0B1y+x+mKTLHkykBgK2KMs3g+KlzmyMbLvICSHQyB/xOFjTT8qZ3oeTFyU7Bbj4FzXitGG6jvKhYw==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/wrap-ansi": {
|
||||
"version": "7.0.0",
|
||||
"dev": true,
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
"@types/color": "^3.0.3",
|
||||
"@types/crypto-js": "^4.2.1",
|
||||
"@types/dateformat": "^5.0.0",
|
||||
"@types/global-agent": "^2.1.3",
|
||||
"@types/got": "^9.6.12",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/node": "22.8.6",
|
||||
@@ -95,6 +96,7 @@
|
||||
"@types/use-double-click": "^1.0.4",
|
||||
"@types/webpack-bundle-analyzer": "^4.4.2",
|
||||
"@types/webpack-env": "^1.18.0",
|
||||
"@types/winreg": "^1.2.36",
|
||||
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
||||
"@typescript-eslint/parser": "^6.20.0",
|
||||
"autoprefixer": "^10.4.17",
|
||||
@@ -170,6 +172,7 @@
|
||||
"format-duration": "^3.0.2",
|
||||
"framer-motion": "^11.2.6",
|
||||
"fs-extra": "^11.2.0",
|
||||
"global-agent": "^3.0.0",
|
||||
"got": "^14.4.4",
|
||||
"history": "^5.3.0",
|
||||
"is-elevated": "^4.0.0",
|
||||
@@ -201,6 +204,7 @@
|
||||
"to-ico": "^1.1.5",
|
||||
"use-double-click": "^1.0.5",
|
||||
"use-fit-text": "^2.4.0",
|
||||
"winreg": "^1.2.5",
|
||||
"yauzl": "^3.2.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import log from 'electron-log';
|
||||
import Winreg from 'winreg';
|
||||
import { bootstrap } from 'global-agent';
|
||||
|
||||
export function configureProxy() {
|
||||
if (process.platform === "win32") {
|
||||
configureWindowsProxy();
|
||||
} else {
|
||||
log.info('configureProxy: Unsupported platform');
|
||||
}
|
||||
}
|
||||
|
||||
async function configureWindowsProxy() {
|
||||
if (await getWindowsProxy()){
|
||||
bootstrap();
|
||||
log.info(`Using system proxy: ${process.env.GLOBAL_AGENT_HTTP_PROXY}`);
|
||||
}
|
||||
}
|
||||
|
||||
function getWindowsProxy() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const regKey = new Winreg({
|
||||
hive: Winreg.HKCU,
|
||||
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'
|
||||
});
|
||||
|
||||
regKey.get('ProxyEnable', (err, result) => {
|
||||
if (err) {
|
||||
log.error('Error accessing registry for ProxyEnable: ', err);
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
// ProxyEnable = 1 means proxy is enabled, 0 means it's disabled
|
||||
if (parseInt(result.value) !== 1) {
|
||||
log.info('Proxy Enabled: false');
|
||||
resolve(false);
|
||||
} else {
|
||||
log.info('Proxy Enabled: true');
|
||||
|
||||
regKey.get('ProxyServer', (err, result) => {
|
||||
if (err) {
|
||||
log.error('Error accessing registry for ProxyServer: ', err);
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
const httpProxyUrl = `http://${result.value}`
|
||||
process.env.GLOBAL_AGENT_HTTP_PROXY = httpProxyUrl;
|
||||
process.env.GLOBAL_AGENT_HTTPS_PROXY = httpProxyUrl;
|
||||
|
||||
log.info('Proxy Server: ', httpProxyUrl);
|
||||
|
||||
regKey.get('ProxyOverride', (err, result) => {
|
||||
if (err) {
|
||||
log.error('Error accessing registry for ProxyOverride: ', err);
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
process.env.GLOBAL_AGENT_NO_PROXY = result.value;
|
||||
|
||||
log.info('Proxy Override: ', result.value);
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import path from 'path';
|
||||
import { pipeline } from 'stream/promises';
|
||||
import sanitize from 'sanitize-filename';
|
||||
import internal from 'stream';
|
||||
import { configureProxy } from 'main/helpers/proxy.helpers';
|
||||
|
||||
export class RequestService {
|
||||
private static instance: RequestService;
|
||||
@@ -23,7 +24,9 @@ export class RequestService {
|
||||
return RequestService.instance;
|
||||
}
|
||||
|
||||
private constructor() {}
|
||||
private constructor() {
|
||||
configureProxy();
|
||||
}
|
||||
|
||||
public async getJSON<T = unknown>(url: string): Promise<{ data: T; headers: IncomingHttpHeaders }> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user