Skip to content

Commit

Permalink
增加几项新的设置
Browse files Browse the repository at this point in the history
  • Loading branch information
xiandanin committed Dec 25, 2019
1 parent 42f5bea commit f8b16ce
Show file tree
Hide file tree
Showing 30 changed files with 573 additions and 529 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
33 changes: 22 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
// https://eslint.org/docs/user-guide/configuring

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
'parser': 'babel-eslint',
'ecmaVersion': 2017,
'sourceType': 'module'
},
env: {
node: true,
browser: true,
node: true
},
extends: 'standard',
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
globals: {
__static: true
},
plugins: [
'html'
'vue'
],
'rules': {
// add your custom rules here
rules: {
// 关闭缩进检查
'indent': 0,
'no-unused-vars': 0,
// allow paren-less arrow functions
'arrow-parens': 0,
'vue/require-v-for-key': 'off',
'no-unused-vars': 'off',
'vue/no-unused-components': 'off',
'vue/valid-v-for': 'warn',
// allow async-await
'generator-star-spacing': 0,
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ workspace.xml
src/dist
Project_Default.xml
package-lock.json
.idea
23 changes: 0 additions & 23 deletions .idea/codeStyles/Project.xml

This file was deleted.

3 changes: 3 additions & 0 deletions src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<head>
<meta charset="utf-8">
<title><%= htmlWebpackPlugin.options.title %> - <%= htmlWebpackPlugin.options.description %></title>
<meta name="robots" content="noindex,nofollow,noarchive">
<meta name="format-detection" content="telephone=no,email=no,adress=no">
<meta http-equiv="window-target" content="_top">
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
Expand Down
12 changes: 6 additions & 6 deletions src/main/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ module.exports = function () {
cloudUrl: '',
// 解析规则文件URL 支持网络链接和本地路径
ruleUrl: 'https://magnetw.app/rule.json',
// 默认最大化窗口
maxWindow: false,
// 是否显示需要代理的源站
showProxyRule: true,
// 记住上次选择的源站
memoryLastRule: false,
// 是否显示源站入口
showSourceLink: false,
// 使用代理
proxy: false,
proxyHost: '127.0.0.1',
proxyPort: '1087',
// 是否启用预加载 启用后会预加载下一页和下一个源站
preload: true,
// 是否启用Tracker 启用后复制链接时会自动拼接Tracker参数
trackers: false,
// Tracker服务器列表的更新地址
trackersUrl: 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt',
// 缓存过期时间
cacheExpired: 7200,
// 追加请求标识
requestIdentifier: true,
// 自定义UserAgent
customUserAgent: false,
customUserAgentValue: null
Expand Down
4 changes: 1 addition & 3 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ function createWindow () {

registerMenu(mainWindow)

const userAgent = mainWindow.webContents.getUserAgent().replace(new RegExp(app.getName(), 'gi'), 'MWBrowser')
const userAgent = mainWindow.webContents.getUserAgent().replace(new RegExp(`${app.getName()}\\/.* `, 'gi'), '')
mainWindow.webContents.setUserAgent(userAgent)
session.defaultSession.setUserAgent(userAgent)
app.setName(build.productName)
mainWindow.loadURL(winURL)

mainWindow.on('closed', () => {
mainWindow = null
})

registerServer()
}

Expand Down
27 changes: 19 additions & 8 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const path = require('path')
const {ipcMain, app} = require('electron')
const request = require('request-promise-native')
const {reload, start} = require('./api')
const processConfig = require('./process-config')
const {defaultConfig, extractConfigVariable, getConfig} = require('./process-config')
const Store = require('electron-store')
const store = new Store()

async function registerServer () {
const configVariable = store.get('config_variable')
const newConfig = processConfig.getConfig(configVariable)
const newConfig = getConfig(configVariable)
configVariable ? console.info('使用自定义配置加载服务', configVariable, newConfig) : console.info('使用默认配置加载服务', configVariable, newConfig)
const {port, ip, local, message} = await start(newConfig)
if (message) {
Expand All @@ -21,7 +21,15 @@ async function registerServer () {
}
}

function getLocalConfig () {
return getConfig(store.get('config_variable'))
}

function registerIPC (mainWindow) {
if (getLocalConfig().maxWindow) {
mainWindow.maximize()
}

ipcMain.on('window-max', function () {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize()
Expand All @@ -33,12 +41,15 @@ function registerIPC (mainWindow) {
* 保存配置
*/
ipcMain.on('save-server-config', async (event, config) => {
const configVariable = processConfig.extractConfigVariable(config)
const newConfig = processConfig.getConfig(configVariable)
const configVariable = extractConfigVariable(config)
const newConfig = getConfig(configVariable)

let err
try {
await reload(newConfig)
// 如果修改了规则url 就重新加载
if (newConfig.ruleUrl !== defaultConfig().ruleUrl) {
await reload(newConfig)
}
} catch (e) {
err = e.message
}
Expand All @@ -54,21 +65,21 @@ function registerIPC (mainWindow) {
* 获取配置信息
*/
ipcMain.on('get-server-config', (event) => {
event.sender.send('on-server-config', processConfig.getConfig(store.get('config_variable')))
event.returnValue = getLocalConfig()
})
/**
* 获取默认配置信息
*/
ipcMain.on('get-default-server-config', (event) => {
event.returnValue = processConfig.defaultConfig()
event.returnValue = defaultConfig()
})
/**
* 检查更新
*/
ipcMain.on('check-update', async (event) => {
try {
const response = await request({
url: processConfig.defaultConfig().checkUpdateURL,
url: defaultConfig().checkUpdateURL,
json: true
})
let newVerArray = response.version.split('.')
Expand Down
2 changes: 1 addition & 1 deletion src/main/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function requestDocument (url, clientHeaders) {
}
const userAgent = clientHeaders['user-agent']
if (userAgent) {
const newUserAgent = /windows|mac|android|ios/gi.test(userAgent) && process.env.npm_package_version ? `${userAgent} MWBrowser/${process.env.npm_package_version}` : userAgent
const newUserAgent = config.requestIdentifier && /windows|mac|android|ios/gi.test(userAgent) && process.env.npm_package_version ? `${userAgent} MWBrowser/${process.env.npm_package_version}` : userAgent
headers['User-Agent'] = config.customUserAgent && config.customUserAgentValue ? config.customUserAgentValue : newUserAgent
}
console.info({url, headers})
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
overflow-x: hidden;
}
}
.header-submenu {
.el-menu--popup {
min-width: 120px !important;
}
}
</style>
92 changes: 50 additions & 42 deletions src/renderer/components/AsideMenu.vue
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
<template>
<div class="aside-menu">
<div class="menu-setting">
<div class="menu-setting-checkbox">
<el-checkbox v-model='localSetting.memoryLastRule'
@change='handleApplySetting' label="记住上次使用的源站" border
size="mini"></el-checkbox>
<el-scrollbar>
<div class="aside-menu">
<div class="menu-setting">
<div class="menu-setting-checkbox">
<el-checkbox v-model='localSetting.memoryLastRule'
@change='handleApplySetting' label="记住上次使用的源站" border
size="mini"></el-checkbox>
</div>
</div>
</div>
<el-menu :default-active="active" @select="emitRuleChangeByID">
<el-menu-item v-for="it in ruleList" :key="it.id" :index="it.id">
<div slot="title" class="menu-item-title">
<el-menu :default-active="active" @select="emitRuleChangeByID">
<el-menu-item v-for="it in ruleList" :key="it.id" :index="it.id">
<div slot="title" class="menu-item-title">
<span class="menu-item-title-text">
<el-image :src="it.icon||formatDefaultIcon(it.id)" class="favicon">
<i slot="placeholder"></i>
<i slot="error"></i>
</el-image>
<span class="source-name">{{it.name}}</span>
</span>
<el-tooltip v-if="it.proxy" effect="dark" placement="right">
<template v-if="localSetting.proxy">
<div slot="content">此源站需要设置代理,已开启代理</div>
<i class="el-icon-connection el-icon-connection-success"></i>
</template>
<template v-else>
<div slot="content">此源站需要设置代理,<span class="tooltip-content-proxy"
@click="handleClickProxyDoc">查看详情</span>
</div>
<i class="el-icon-connection"></i>
</template>
</el-tooltip>
</div>
</el-menu-item>
</el-menu>
</div>
<el-tooltip v-if="it.proxy" effect="dark" placement="right">
<template v-if="config.proxy">
<div slot="content">此源站需要设置代理,已开启代理</div>
<i class="el-icon-connection el-icon-connection-success"></i>
</template>
<template v-else>
<div slot="content">此源站需要设置代理,
<browser-link class="tooltip-content-proxy"
:href="$config.proxyDocURL" type="primary">查看详情
</browser-link>
</div>
<i class="el-icon-connection"></i>
</template>
</el-tooltip>
</div>
</el-menu-item>
</el-menu>
</div>
</el-scrollbar>
</template>

<script>
import {ipcRenderer} from 'electron'
import ruleList from '~/rule'
import axios from '@/plugins/axios'
import BrowserLink from './BrowserLink'
export default {
components: {BrowserLink},
props: {
active: String
},
data () {
return {
ruleList: ruleList,
ruleList: this.$localSetting.get('rule_list') || ruleList,
localSetting: {
memoryLastRule: false
}
},
config: ipcRenderer.sendSync('get-server-config')
}
},
watch: {
Expand All @@ -68,6 +76,18 @@
}
this.$emit('change', active)
},
handleRefreshActiveRule () {
const localSetting = this.$localSetting.get()
if (Object.keys(localSetting).length > 0) {
this.localSetting = localSetting
}
let active = this.active
if (localSetting.memoryLastRule && localSetting.last_rule_id) {
active = localSetting.last_rule_id
}
this.emitRuleChangeByID(active)
},
handleClickProxyDoc () {
window.open(this.$config.proxyDocURL)
},
Expand All @@ -81,6 +101,7 @@
axios.get('/rule').then((rsp) => {
this.$localSetting.saveValue('rule_list', rsp.data)
this.ruleList = rsp.data
this.handleRefreshActiveRule()
this.$emit('rule-refresh-finished', rsp.data)
}).catch((err) => {
this.$emit('rule-refresh-finished', null, err)
Expand All @@ -91,27 +112,14 @@
created () {
},
mounted () {
const localSetting = this.$localSetting.get()
if (Object.keys(localSetting).length > 0) {
this.localSetting = localSetting
}
let active = this.active
if (localSetting.memoryLastRule && localSetting.last_rule_id) {
active = localSetting.last_rule_id
}
this.emitRuleChangeByID(active)
this.handleRefreshActiveRule()
this.handleReloadRules()
}
}
</script>

<style lang="scss">
.el-scrollbar__view {
height: 100%;
}
.el-scrollbar {
border-right: solid 1px $color-border;
}
Expand Down
Loading

0 comments on commit f8b16ce

Please sign in to comment.