mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Add toggle-able system proxy setting
This commit is contained in:
@@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +277,18 @@
|
||||
"error-notification": {
|
||||
"message": "发生错误,无法更改符号链接设置。"
|
||||
}
|
||||
},
|
||||
"use-system-proxy": {
|
||||
"title": "使用系统代理",
|
||||
"description": "BSMansger将通过系统代理发起网络请求。",
|
||||
"modal": {
|
||||
"title": "需要重启",
|
||||
"body": "关闭系统代理需要退出并重新启动BSManager。您确定要这样做吗?",
|
||||
"confirm-btn": "是的,我确定"
|
||||
},
|
||||
"error-notification": {
|
||||
"message": "发生错误,无法启用系统代理。"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<void> {
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <SettingContainer title="pages.settings.advanced.title" description="pages.settings.advanced.description">
|
||||
|
||||
Reference in New Issue
Block a user