From 5b6619d1deb79f59894575559fd14db30633737d Mon Sep 17 00:00:00 2001 From: qier222 Date: Mon, 17 May 2021 19:04:14 +0800 Subject: [PATCH] fix: proxy issue --- src/background.js | 8 ++++++++ src/electron/ipcMain.js | 3 ++- src/utils/request.js | 6 ++++++ src/views/settings.vue | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index aba3ee1..050184b 100644 --- a/src/background.js +++ b/src/background.js @@ -247,6 +247,14 @@ class Background { // init ipcMain 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 this.checkForUpdates(); diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index c8fa912..107e830 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -105,8 +105,8 @@ export function initIpcMain(win, store) { }); ipcMain.on('setProxy', (event, config) => { - console.log(config); const proxyRules = `${config.protocol}://${config.server}:${config.port}`; + store.set('proxy', proxyRules); win.webContents.session.setProxy( { proxyRules, @@ -120,5 +120,6 @@ export function initIpcMain(win, store) { ipcMain.on('removeProxy', (event, arg) => { console.log('removeProxy'); win.webContents.session.setProxy({}); + store.set('proxy', ''); }); } diff --git a/src/utils/request.js b/src/utils/request.js index f496e59..a263430 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -24,6 +24,12 @@ service.interceptors.request.use(function (config) { if (baseURL[0] !== '/' && !process.env.IS_ELECTRON) { 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; }); diff --git a/src/views/settings.vue b/src/views/settings.vue index 7fe858b..a9b0b5b 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -362,7 +362,7 @@ - +