setup system proxy on initilized
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
1
enjoy/src/types/enjoy-app.d.ts
vendored
1
enjoy/src/types/enjoy-app.d.ts
vendored
@@ -27,6 +27,7 @@ type EnjoyAppType = {
|
||||
proxy: {
|
||||
get: () => Promise<ProxyConfigType>;
|
||||
set: (config: ProxyConfigType) => Promise<void>;
|
||||
refresh: () => Promise<void>;
|
||||
};
|
||||
};
|
||||
providers: {
|
||||
|
||||
Reference in New Issue
Block a user