fix: proxy issue

master
qier222 4 years ago
parent cc6b364b87
commit 5b6619d1de
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D

@ -247,6 +247,14 @@ class Background {
// init ipcMain // init ipcMain
initIpcMain(this.window, this.store); initIpcMain(this.window, this.store);
// set proxy
const proxyRules = this.store.get('proxy');
if (proxyRules) {
this.window.webContents.session.setProxy({ proxyRules }, result => {
console.log('finished setProxy', result);
});
}
// check for updates // check for updates
this.checkForUpdates(); this.checkForUpdates();

@ -105,8 +105,8 @@ export function initIpcMain(win, store) {
}); });
ipcMain.on('setProxy', (event, config) => { ipcMain.on('setProxy', (event, config) => {
console.log(config);
const proxyRules = `${config.protocol}://${config.server}:${config.port}`; const proxyRules = `${config.protocol}://${config.server}:${config.port}`;
store.set('proxy', proxyRules);
win.webContents.session.setProxy( win.webContents.session.setProxy(
{ {
proxyRules, proxyRules,
@ -120,5 +120,6 @@ export function initIpcMain(win, store) {
ipcMain.on('removeProxy', (event, arg) => { ipcMain.on('removeProxy', (event, arg) => {
console.log('removeProxy'); console.log('removeProxy');
win.webContents.session.setProxy({}); win.webContents.session.setProxy({});
store.set('proxy', '');
}); });
} }

@ -24,6 +24,12 @@ service.interceptors.request.use(function (config) {
if (baseURL[0] !== '/' && !process.env.IS_ELECTRON) { if (baseURL[0] !== '/' && !process.env.IS_ELECTRON) {
config.params.cookie = `MUSIC_U=${Cookies.get('MUSIC_U')};`; config.params.cookie = `MUSIC_U=${Cookies.get('MUSIC_U')};`;
} }
const proxy = JSON.parse(localStorage.getItem('settings')).proxyConfig;
if (['HTTP', 'HTTPS'].includes(proxy.protocol)) {
config.params.proxy = `${proxy.protocol}://${proxy.server}:${proxy.port}`;
}
return config; return config;
}); });

@ -362,7 +362,7 @@
<option value="noProxy"> 关闭代理 </option> <option value="noProxy"> 关闭代理 </option>
<option value="HTTP"> HTTP 代理 </option> <option value="HTTP"> HTTP 代理 </option>
<option value="HTTPS"> HTTPS 代理 </option> <option value="HTTPS"> HTTPS 代理 </option>
<option value="SOCKS"> SOCKS 代理 </option> <!-- <option value="SOCKS"> SOCKS 代理 </option> -->
</select> </select>
</div> </div>
</div> </div>

Loading…
Cancel
Save