diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index 1ef9eab9..8e0be61b 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -277,6 +277,18 @@ "error-notification": { "message": "An error occured, unable to change symlinks settings." } + }, + "use-system-proxy": { + "title": "Use system proxy", + "description": "BSMansger will make network requests through system proxy.", + "modal": { + "title": "Restart Needed", + "body": "Turning off system proxy will quit and re-launch BSManager. Are you sure you want to do this?", + "confirm-btn": "Yes I'm sure" + }, + "error-notification": { + "message": "An error occured, unable to use system proxy." + } } } } diff --git a/assets/jsons/translations/zh.json b/assets/jsons/translations/zh.json index a84ec492..7ef94df1 100644 --- a/assets/jsons/translations/zh.json +++ b/assets/jsons/translations/zh.json @@ -277,6 +277,18 @@ "error-notification": { "message": "发生错误,无法更改符号链接设置。" } + }, + "use-system-proxy": { + "title": "使用系统代理", + "description": "BSMansger将通过系统代理发起网络请求。", + "modal": { + "title": "需要重启", + "body": "关闭系统代理需要退出并重新启动BSManager。您确定要这样做吗?", + "confirm-btn": "是的,我确定" + }, + "error-notification": { + "message": "发生错误,无法启用系统代理。" + } } } } diff --git a/src/main/helpers/proxy.helpers.ts b/src/main/helpers/proxy.helpers.ts index ea2810b2..ba4ec320 100644 --- a/src/main/helpers/proxy.helpers.ts +++ b/src/main/helpers/proxy.helpers.ts @@ -2,6 +2,9 @@ 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"); @@ -51,7 +54,21 @@ async function configureWindowsProxy() : Promise { export function configureProxy() { if (process.platform === "win32") { - configureWindowsProxy(); + const useSystemProxy = staticConfig.get("use-system-proxy"); + + if (useSystemProxy === true) { + configureWindowsProxy(); + } + + log.info(`configureProxy: UseSystemProxy is set to ${useSystemProxy}`); + + staticConfig.$watch("use-system-proxy").subscribe((useSystemProxy) => { + if (useSystemProxy === true) { + configureWindowsProxy(); + } + + log.info(`configureProxy: UseSystemProxy is set to ${useSystemProxy}`); + }); } else { log.info('configureProxy: Unsupported platform'); } diff --git a/src/main/services/static-configuration.service.ts b/src/main/services/static-configuration.service.ts index 1748b42d..0a90c607 100644 --- a/src/main/services/static-configuration.service.ts +++ b/src/main/services/static-configuration.service.ts @@ -88,6 +88,7 @@ export interface StaticConfigKeyValues { "song-details-cache-etag": string; "disable-hadware-acceleration": boolean; "use-symlinks": boolean; + "use-system-proxy": boolean; // Linux Specific static configs "proton-folder": string; diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index 991c4ece..cd26de6d 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -541,10 +541,12 @@ function AdvancedSettings() { const [hardwareAccelerationEnabled, setHardwareAccelerationEnabled] = useState(true); const [useSymlink, setUseSymlink] = useState(false); + const [useSystemProxy, setUseSystemProxy] = useState(false); useEffect(() => { staticConfig.get("disable-hadware-acceleration").then(disabled =>setHardwareAccelerationEnabled(() => disabled !== true)); staticConfig.get("use-symlinks").then(useSymlinks => setUseSymlink(() => useSymlinks)); + staticConfig.get("use-system-proxy").then(useSystemProxy => setUseSystemProxy(() => useSystemProxy)); }, []); const onChangeHardwareAcceleration = async (newHardwareAccelerationEnabled: boolean) => { @@ -609,6 +611,45 @@ function AdvancedSettings() { setUseSymlink(() => newUseSymlink); } + const onChangeUseSystemProxy = async (newUseSystemProxy: boolean) => { + + if (window.electron.platform !== "win32" || newUseSystemProxy === useSystemProxy) { + 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){ + notification.notifyError({ title: "notifications.types.error", desc: "pages.settings.advanced.use-system-proxy.error-notification.message" }); + return; + } + + setUseSystemProxy(() => newUseSystemProxy); + + if(!progressBar.require()){ + return; + } + + if (!newUseSystemProxy) { + await lastValueFrom(ipc.sendV2("restart-app")); + } + + } + const advancedItems: Item[] = [{ checked: hardwareAccelerationEnabled, text: t.text("pages.settings.advanced.hardware-acceleration.title"), @@ -622,6 +663,12 @@ function AdvancedSettings() { desc: t.text("pages.settings.advanced.use-symlinks.description"), onChange: onChangeUseSymlinks }); + advancedItems.push({ + checked: useSystemProxy, + text: t.text("pages.settings.advanced.use-system-proxy.title"), + desc: t.text("pages.settings.advanced.use-system-proxy.description"), + onChange: onChangeUseSystemProxy + }); } return