Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.

Commit

Permalink
升级electron;自动分配端口
Browse files Browse the repository at this point in the history
  • Loading branch information
xiandanin committed Jan 10, 2020
1 parent 1863968 commit d9ddbdd
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Project_Default.xml
package-lock.json
.idea
scripts/filter-data/.temp
build/icons/.icns.iconset
Binary file modified build/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified build/icons/icon.icns
Binary file not shown.
Binary file modified build/icons/icon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions icns.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
# brew install icoutils
filepath=256x256.png
iconset=.icns.iconset

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "magnetw",
"version": "3.1.0",
"appName": "magnetw",
"description": "磁力链接聚合搜索",
"license": "GNU General Public License v3.0",
"main": "./dist/electron/main.js",
Expand All @@ -19,6 +18,7 @@
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": "npm run lint:fix",
"ins": "npm install --no-optional",
"export-filter-db": "node scripts/export-filter-db.js"
},
"build": {
Expand Down Expand Up @@ -89,7 +89,7 @@
"socks5-https-client": "^1.2.1",
"sqlite3": "^4.1.1",
"urijs": "^1.19.2",
"vue": "^2.6.10",
"vue": "^2.6.11",
"vue-clipboard2": "^0.3.1",
"vue-electron": "^1.0.6",
"vue-event-proxy": "^1.0.5",
Expand Down Expand Up @@ -118,11 +118,11 @@
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-builder": "^20.19.2",
"electron": "^7.1.8",
"electron-builder": "^21.2.0",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"element-ui": "^2.12.0",
"element-ui": "^2.13.0",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^4.0.1",
Expand Down
8 changes: 4 additions & 4 deletions src/main/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ async function reload (config, preload) {

async function start (config, preload) {
try {
const port = config.port || 9000
koaServer = app.listen(port)

const port = config.port
koaServer = await app.listen(port)
const address = koaServer.address()
serverInfo = {
port,
port: address.port,
ip: getIPAddress(),
local: 'localhost'
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function createWindow () {
minHeight: 550,
frame: true,
titleBarStyle: 'hidden',
show: false
backgroundColor: '#fff',
show: false,
webPreferences: {
nodeIntegration: true
}
})
// 是否设置最大化
const configVariable = store.get('config_variable')
Expand All @@ -45,10 +49,9 @@ function createWindow () {
}
mainWindow.show()

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

registerMenu(mainWindow)

Expand Down
5 changes: 3 additions & 2 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const logger = require('./logger')
const path = require('path')
const {ipcMain, app} = require('electron')
const request = require('request-promise-native')
const {reload, start, isStarting, getProxyNetworkInfo} = require('./api')
const {reload, start, isStarting, getProxyNetworkInfo, getServerInfo} = require('./api')
const {defaultConfig, extractConfigVariable, getConfig} = require('./process-config')
const is = require('electron-is')
const Store = require('electron-store')
Expand Down Expand Up @@ -104,7 +104,8 @@ function registerIPC (mainWindow) {
*/
ipcMain.on('get-app-info', (event) => {
event.returnValue = {
logDir: path.resolve(logger.transports.file.file, '..')
logDir: path.resolve(logger.transports.file.file, '..'),
server: getServerInfo()
}
})

Expand Down
8 changes: 4 additions & 4 deletions src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ module.exports = function (mainWindow) {
},
{type: 'separator'}
] : []),
/* {label: `关于 ${app.getName()}`, role: 'about'}, */
/* {label: `关于 ${app.name}`, role: 'about'}, */
{label: '清除缓存', click: () => session.defaultSession.clearCache(() => console.info('清除完成'))},
{type: 'separator'},
...(is.macOS() ? [
{label: `隐藏 ${app.getName()}`, role: 'hide'},
{label: `隐藏 ${app.name}`, role: 'hide'},
{label: '隐藏其他应用', role: 'hideothers'},
{label: '显示全部', role: 'unhide'},
{type: 'separator'}
] : []),
{label: `退出 ${app.getName()}`, role: 'quit'}
{label: `退出 ${app.name}`, role: 'quit'}
]
const windowMenu = [
{label: '重新加载', role: 'reload'},
Expand Down Expand Up @@ -59,7 +59,7 @@ module.exports = function (mainWindow) {
]
const menu = Menu.buildFromTemplate([
{
label: app.getName(),
label: app.name,
submenu: appSubmenu
},
{
Expand Down
Binary file removed src/renderer/assets/logo.png
Binary file not shown.
28 changes: 28 additions & 0 deletions src/renderer/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/renderer/assets/scss/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ body {
-webkit-app-region: no-drag;
}

.el-button, .el-radio__label, .el-checkbox__label {
font-weight: normal;
}

.el-button [class*="iconfont"] + span {
margin-left: 5px;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/HeaderVersion.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<browser-link href="/" target="_self">
<div class="header-version align-items-center">
<img src="../assets/logo.png" width="36" height="36"/>
<img src="../assets/logo.svg" width="36" height="36"/>
<div>
<div class="header-version-text">{{ appName }}</div>
<div class="header-version-text">v{{ version }}</div>
Expand Down
24 changes: 24 additions & 0 deletions src/renderer/components/ServerConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
</el-row>
</tooltip-form-item>
<div v-show="!config.cloud">
<el-form-item label="服务状态">
<div v-if="appInfo.server" class="server-status-success">
<span>IP: {{appInfo.server.ip}}</span>
<span class="server-status-success-value">端口: {{appInfo.server.port}}</span>
</div>
<div v-else class="server-status-error">{{appInfo.server.message||'服务启动失败,请查看日志'}}</div>
</el-form-item>
<tooltip-form-item label="规则同步URL" tooltip="解析源站的规则文件URL,支持网络链接和本地路径">
<el-input :size="formSize" v-model="config.ruleUrl" :placeholder="defaultConfig.ruleUrl"></el-input>
</tooltip-form-item>
Expand Down Expand Up @@ -199,4 +206,21 @@
}
}
.config-item-title {
font-size: 20px;
font-weight: bolder;
color: $--color-text-primary;
}
.server-status-error {
color: $--color-danger;
}
.server-status-success {
color: $--color-success
}
.server-status-success-value {
margin-left: 15px;
}
</style>

1 comment on commit d9ddbdd

@xiandanin
Copy link
Owner Author

@xiandanin xiandanin commented on d9ddbdd Jan 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#75 #73

Please sign in to comment.