From a887968458fd8d1759bce92baac360924a0f9c2f Mon Sep 17 00:00:00 2001 From: buvta <12312540+buvta@users.noreply.github.com> Date: Fri, 13 Nov 2020 20:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=A2=9E=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Setting.vue | 66 ++++++++++++++++++++++++++------------ src/lib/dexie/dexie.js | 2 +- src/lib/dexie/initData.js | 8 ++++- src/lib/site/tools.js | 26 ++++++++++++--- 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/components/Setting.vue b/src/components/Setting.vue index ef18a11..01a9f1b 100644 --- a/src/components/Setting.vue +++ b/src/components/Setting.vue @@ -86,8 +86,15 @@
网络
-
-
代理设置
+
+
代理设置
+
+
    +
  • 不使用代理
  • + +
  • 手动指定代理
  • +
+
@@ -163,15 +170,13 @@
- + - - - + @@ -179,17 +184,14 @@ - - + : - - - - 取消 + 取消 确定 @@ -203,6 +205,7 @@ import { setting, sites, shortcut } from '../lib/dexie' import { sites as defaultSites } from '../lib/dexie/initData' import { shell, clipboard, remote, ipcRenderer } from 'electron' import db from '../lib/dexie/dexie' +import zy from '../lib/site/tools' export default { name: 'setting', data () { @@ -216,6 +219,7 @@ export default { editPlayerPath: false, checkPasswordDialog: false, changePasswordDialog: false, + proxy: false, proxyDialog: false }, d: { }, @@ -223,10 +227,10 @@ export default { inputPassword: '', action: '', proxy: { + type: '', scheme: '', - ip: '', - port: '', - state: false + url: '', + port: '' } } }, @@ -340,6 +344,12 @@ export default { closeDialog () { this.show.checkPasswordDialog = false this.show.changePasswordDialog = false + if (this.show.proxyDialog) { + this.show.proxyDialog = false + this.setting.proxy.type = 'none' + this.updateSettingEvent() + this.$message.info('未使用代理') + } this.inputPassword = '' }, checkPasswordEvent () { @@ -395,6 +405,27 @@ export default { }) }) }, + async changeProxyType (e) { + this.d.proxy.type = e + if (e === 'manual') { + this.show.proxyDialog = true + this.proxy.scheme = this.setting.proxy.scheme + this.proxy.url = this.setting.proxy.url + this.proxy.port = this.setting.proxy.port + } + await this.updateSettingEvent() + this.show.proxy = false + zy.proxy() + }, + async proxyConfirm () { + this.d.proxy.scheme = this.proxy.scheme + this.d.proxy.url = this.proxy.url + this.d.proxy.port = this.proxy.port + await this.updateSettingEvent() + this.show.proxyDialog = false + await zy.proxy() + this.$message.info('开始使用代理') + }, clearDBEvent () { if (this.d.password) { this.action = 'CleanDB' @@ -446,12 +477,7 @@ export default { e.preventDefault() menu.popup(remote.getCurrentWindow()) }) - }, - editProxyEvent () { - this.show.proxyDialog = true - }, - closeProxyDialog () {}, - proxyConfirm () {} + } }, created () { this.getSites() diff --git a/src/lib/dexie/dexie.js b/src/lib/dexie/dexie.js index 79955a1..478a0cc 100644 --- a/src/lib/dexie/dexie.js +++ b/src/lib/dexie/dexie.js @@ -6,7 +6,7 @@ const db = new Dexie('zy') db.version(4).stores({ search: '++id, keywords', iptvSearch: '++id, keywords', - setting: 'id, theme, site, shortcut, view, externalPlayer, searchGroup, excludeRootClasses, excludeR18Films, forwardTimeInSec, starViewMode, recommandationViewMode, password', + setting: 'id, theme, site, shortcut, view, externalPlayer, searchGroup, excludeRootClasses, excludeR18Films, forwardTimeInSec, starViewMode, recommandationViewMode, password, proxy', shortcut: 'name, key, desc', star: '++id, [key+ids], site, name, detail, index, rate, hasUpdate', recommendation: '++id, [key+ids], site, name, detail, index, rate, hasUpdate', diff --git a/src/lib/dexie/initData.js b/src/lib/dexie/initData.js index 0204ff7..6889237 100644 --- a/src/lib/dexie/initData.js +++ b/src/lib/dexie/initData.js @@ -12,7 +12,13 @@ const setting = [ starViewMode: 'picture', recommendationViewMode: 'picture', historyViewMode: 'picture', - password: '' + password: '', + proxy: { + type: 'none', + scheme: '', + url: '', + port: '' + } } ] diff --git a/src/lib/site/tools.js b/src/lib/site/tools.js index 6266ec3..7c5aad5 100644 --- a/src/lib/site/tools.js +++ b/src/lib/site/tools.js @@ -1,4 +1,4 @@ -import { sites } from '../dexie' +import { sites, setting } from '../dexie' import axios from 'axios' import parser from 'fast-xml-parser' import cheerio from 'cheerio' @@ -14,9 +14,6 @@ var win = remote.getCurrentWindow() var session = win.webContents.session var ElectronProxyAgent = require('electron-proxy-agent') -// use ElectronProxyAgent as http and https globalAgents -http.globalAgent = https.globalAgent = new ElectronProxyAgent(session) - // 请求超时时限 axios.defaults.timeout = 10000 // 可能使用代理,增长超时 @@ -373,7 +370,28 @@ const zy = { reject(err) }) }) + }, + async proxy () { + return new Promise((resolve, reject) => { + setting.find().then(db => { + if (db.proxy) { + if (db.proxy.type === 'none') { + session.setProxy({ proxyRules: 'direct://' }) + } else if (db.proxy.type === 'manual') { + if (db.proxy.scheme && db.proxy.url && db.proxy.port) { + const proxyURL = db.proxy.scheme + '://' + db.proxy.url.trim() + ':' + db.proxy.port.trim() + session.setProxy({ proxyRules: proxyURL }) + http.globalAgent = https.globalAgent = new ElectronProxyAgent(session) + } + } + } + // 不要删了,留着测试用 + // axios.get('https://api.my-ip.io/ip').then(res => console.log(res)) + }) + }) } } +zy.proxy() + export default zy