setup system proxy on initilized

This commit is contained in:
an-lee
2024-10-15 10:24:33 +08:00
parent 5f5811bc9c
commit 9e974e977e
4 changed files with 21 additions and 6 deletions

View File

@@ -104,10 +104,21 @@ main.init = async () => {
throw new Error("Invalid proxy config");
}
if (config) {
if (!config.url) {
config.enabled = false;
}
if (config && !config.url) {
config.enabled = false;
}
return settings.setSync("proxy", config);
});
ipcMain.handle("system-proxy-refresh", (_event) => {
let config = settings.getSync("proxy") as ProxyConfigType;
if (!config) {
config = {
enabled: false,
url: "",
};
settings.setSync("proxy", config);
}
if (config.enabled && config.url) {
@@ -124,8 +135,6 @@ main.init = async () => {
});
mainWindow.webContents.session.closeAllConnections();
}
return settings.setSync("proxy", config);
});
// BrowserView

View File

@@ -76,6 +76,9 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", {
set: (config: ProxyConfigType) => {
return ipcRenderer.invoke("system-proxy-set", config);
},
refresh: () => {
return ipcRenderer.invoke("system-proxy-refresh");
},
},
},
providers: {

View File

@@ -162,11 +162,13 @@ export const AppSettingsProvider = ({
const fetchProxyConfig = async () => {
const config = await EnjoyApp.system.proxy.get();
setProxy(config);
EnjoyApp.system.proxy.refresh();
};
const setProxyConfigHandler = async (config: ProxyConfigType) => {
EnjoyApp.system.proxy.set(config).then(() => {
setProxy(config);
EnjoyApp.system.proxy.refresh();
});
};

View File

@@ -27,6 +27,7 @@ type EnjoyAppType = {
proxy: {
get: () => Promise<ProxyConfigType>;
set: (config: ProxyConfigType) => Promise<void>;
refresh: () => Promise<void>;
};
};
providers: {