mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-23 03:31:56 +00:00
proxy: Migration to use async/await.
This is required for the upgrade to Electron 7, which removes the old callback-based form of these APIs.
This commit is contained in:
@@ -153,33 +153,31 @@ class ServerManagerView {
|
||||
});
|
||||
}
|
||||
|
||||
loadProxy(): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
// To change proxyEnable to useManualProxy in older versions
|
||||
const proxyEnabledOld = ConfigUtil.isConfigItemExists('useProxy');
|
||||
if (proxyEnabledOld) {
|
||||
const proxyEnableOldState = ConfigUtil.getConfigItem('useProxy');
|
||||
if (proxyEnableOldState) {
|
||||
ConfigUtil.setConfigItem('useManualProxy', true);
|
||||
}
|
||||
ConfigUtil.removeConfigItem('useProxy');
|
||||
async loadProxy(): Promise<void> {
|
||||
// To change proxyEnable to useManualProxy in older versions
|
||||
const proxyEnabledOld = ConfigUtil.isConfigItemExists('useProxy');
|
||||
if (proxyEnabledOld) {
|
||||
const proxyEnableOldState = ConfigUtil.getConfigItem('useProxy');
|
||||
if (proxyEnableOldState) {
|
||||
ConfigUtil.setConfigItem('useManualProxy', true);
|
||||
}
|
||||
ConfigUtil.removeConfigItem('useProxy');
|
||||
}
|
||||
|
||||
const proxyEnabled = ConfigUtil.getConfigItem('useManualProxy') || ConfigUtil.getConfigItem('useSystemProxy');
|
||||
if (proxyEnabled) {
|
||||
session.fromPartition('persist:webviewsession').setProxy({
|
||||
pacScript: ConfigUtil.getConfigItem('proxyPAC', ''),
|
||||
proxyRules: ConfigUtil.getConfigItem('proxyRules', ''),
|
||||
proxyBypassRules: ConfigUtil.getConfigItem('proxyBypass', '')
|
||||
}, resolve);
|
||||
} else {
|
||||
session.fromPartition('persist:webviewsession').setProxy({
|
||||
pacScript: '',
|
||||
proxyRules: '',
|
||||
proxyBypassRules: ''
|
||||
}, resolve);
|
||||
}
|
||||
});
|
||||
const proxyEnabled = ConfigUtil.getConfigItem('useManualProxy') || ConfigUtil.getConfigItem('useSystemProxy');
|
||||
if (proxyEnabled) {
|
||||
await session.fromPartition('persist:webviewsession').setProxy({
|
||||
pacScript: ConfigUtil.getConfigItem('proxyPAC', ''),
|
||||
proxyRules: ConfigUtil.getConfigItem('proxyRules', ''),
|
||||
proxyBypassRules: ConfigUtil.getConfigItem('proxyBypass', '')
|
||||
});
|
||||
} else {
|
||||
await session.fromPartition('persist:webviewsession').setProxy({
|
||||
pacScript: '',
|
||||
proxyRules: '',
|
||||
proxyBypassRules: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Settings are initialized only when user clicks on General/Server/Network section settings
|
||||
|
@@ -67,63 +67,59 @@ class ProxyUtil {
|
||||
const resolveProxyUrl = 'www.example.com';
|
||||
|
||||
// Check HTTP Proxy
|
||||
const httpProxy = new Promise(resolve => {
|
||||
ses.resolveProxy('http://' + resolveProxyUrl, (proxy: string) => {
|
||||
let httpString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
|
||||
// for all other HTTP or direct url:port both uses PROXY
|
||||
if (proxy.includes('PROXY') || proxy.includes('HTTPS')) {
|
||||
httpString = 'http=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
const httpProxy = (async () => {
|
||||
const proxy = await ses.resolveProxy('http://' + resolveProxyUrl);
|
||||
let httpString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
|
||||
// for all other HTTP or direct url:port both uses PROXY
|
||||
if (proxy.includes('PROXY') || proxy.includes('HTTPS')) {
|
||||
httpString = 'http=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
resolve(httpString);
|
||||
});
|
||||
});
|
||||
}
|
||||
return httpString;
|
||||
})();
|
||||
// Check HTTPS Proxy
|
||||
const httpsProxy = new Promise(resolve => {
|
||||
ses.resolveProxy('https://' + resolveProxyUrl, (proxy: string) => {
|
||||
let httpsString = '';
|
||||
if (proxy !== 'DIRECT' || proxy.includes('HTTPS')) {
|
||||
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
|
||||
// for all other HTTP or direct url:port both uses PROXY
|
||||
if (proxy.includes('PROXY') || proxy.includes('HTTPS')) {
|
||||
httpsString += 'https=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
const httpsProxy = (async () => {
|
||||
const proxy = await ses.resolveProxy('https://' + resolveProxyUrl);
|
||||
let httpsString = '';
|
||||
if (proxy !== 'DIRECT' || proxy.includes('HTTPS')) {
|
||||
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
|
||||
// for all other HTTP or direct url:port both uses PROXY
|
||||
if (proxy.includes('PROXY') || proxy.includes('HTTPS')) {
|
||||
httpsString += 'https=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
resolve(httpsString);
|
||||
});
|
||||
});
|
||||
}
|
||||
return httpsString;
|
||||
})();
|
||||
|
||||
// Check FTP Proxy
|
||||
const ftpProxy = new Promise(resolve => {
|
||||
ses.resolveProxy('ftp://' + resolveProxyUrl, (proxy: string) => {
|
||||
let ftpString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
if (proxy.includes('PROXY')) {
|
||||
ftpString += 'ftp=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
const ftpProxy = (async () => {
|
||||
const proxy = await ses.resolveProxy('ftp://' + resolveProxyUrl);
|
||||
let ftpString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
if (proxy.includes('PROXY')) {
|
||||
ftpString += 'ftp=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
resolve(ftpString);
|
||||
});
|
||||
});
|
||||
}
|
||||
return ftpString;
|
||||
})();
|
||||
|
||||
// Check SOCKS Proxy
|
||||
const socksProxy = new Promise(resolve => {
|
||||
ses.resolveProxy('socks4://' + resolveProxyUrl, (proxy: string) => {
|
||||
let socksString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
if (proxy.includes('SOCKS5')) {
|
||||
socksString += 'socks=' + proxy.split('SOCKS5')[1] + ';';
|
||||
} else if (proxy.includes('SOCKS4')) {
|
||||
socksString += 'socks=' + proxy.split('SOCKS4')[1] + ';';
|
||||
} else if (proxy.includes('PROXY')) {
|
||||
socksString += 'socks=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
const socksProxy = (async () => {
|
||||
const proxy = await ses.resolveProxy('socks4://' + resolveProxyUrl);
|
||||
let socksString = '';
|
||||
if (proxy !== 'DIRECT') {
|
||||
if (proxy.includes('SOCKS5')) {
|
||||
socksString += 'socks=' + proxy.split('SOCKS5')[1] + ';';
|
||||
} else if (proxy.includes('SOCKS4')) {
|
||||
socksString += 'socks=' + proxy.split('SOCKS4')[1] + ';';
|
||||
} else if (proxy.includes('PROXY')) {
|
||||
socksString += 'socks=' + proxy.split('PROXY')[1] + ';';
|
||||
}
|
||||
resolve(socksString);
|
||||
});
|
||||
});
|
||||
}
|
||||
return socksString;
|
||||
})();
|
||||
|
||||
Promise.all([httpProxy, httpsProxy, ftpProxy, socksProxy]).then(values => {
|
||||
let proxyString = '';
|
||||
|
Reference in New Issue
Block a user