perf: 支持日志文件
parent
83276a328f
commit
a4ce3fd138
|
@ -16,6 +16,7 @@
|
||||||
"start": "node ./start"
|
"start": "node ./start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"log4js": "^6.3.0",
|
||||||
"@docmirror/mitmproxy": "^1.1.0",
|
"@docmirror/mitmproxy": "^1.1.0",
|
||||||
"agentkeepalive": "^2.1.1",
|
"agentkeepalive": "^2.1.1",
|
||||||
"charset": "^1.0.0",
|
"charset": "^1.0.0",
|
||||||
|
|
|
@ -6,12 +6,14 @@ const modules = require('./modules')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const proxyServer = require('@docmirror/mitmproxy')
|
const proxyServer = require('@docmirror/mitmproxy')
|
||||||
const proxyConfig = proxyServer.config
|
const proxyConfig = proxyServer.config
|
||||||
|
const log = require('./utils/util.log')
|
||||||
const context = {
|
const context = {
|
||||||
config,
|
config,
|
||||||
shell,
|
shell,
|
||||||
status,
|
status,
|
||||||
event,
|
event,
|
||||||
rootCaFile: proxyConfig.getDefaultCACertPath()
|
rootCaFile: proxyConfig.getDefaultCACertPath(),
|
||||||
|
log
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupPlugin (key, plugin, context, config) {
|
function setupPlugin (key, plugin, context, config) {
|
||||||
|
@ -43,14 +45,14 @@ module.exports = {
|
||||||
try {
|
try {
|
||||||
await server.start({ mitmproxyPath })
|
await server.start({ mitmproxyPath })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('代理服务启动失败:', err)
|
log.error('代理服务启动失败:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conf.proxy.enabled) {
|
if (conf.proxy.enabled) {
|
||||||
try {
|
try {
|
||||||
await proxy.start()
|
await proxy.start()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('开启系统代理失败:', err)
|
log.error('开启系统代理失败:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -60,9 +62,9 @@ module.exports = {
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
try {
|
try {
|
||||||
await plugin[key].start()
|
await plugin[key].start()
|
||||||
console.log(`插件【${key}】已启动`)
|
log.info(`插件【${key}】已启动`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`插件【${key}】启动失败`, err)
|
log.error(`插件【${key}】启动失败`, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugins.push(start())
|
plugins.push(start())
|
||||||
|
@ -72,7 +74,7 @@ module.exports = {
|
||||||
await Promise.all(plugins)
|
await Promise.all(plugins)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('开启插件失败:', err)
|
log.error('开启插件失败:', err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
shutdown: async () => {
|
shutdown: async () => {
|
||||||
|
@ -83,9 +85,9 @@ module.exports = {
|
||||||
const close = async () => {
|
const close = async () => {
|
||||||
try {
|
try {
|
||||||
await plugin[key].close()
|
await plugin[key].close()
|
||||||
console.log(`插件【${key}】已关闭`)
|
log.info(`插件【${key}】已关闭`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`插件【${key}】关闭失败`, err)
|
log.info(`插件【${key}】关闭失败`, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugins.push(close())
|
plugins.push(close())
|
||||||
|
@ -95,23 +97,23 @@ module.exports = {
|
||||||
await Promise.all(plugins)
|
await Promise.all(plugins)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('插件关闭失败'.error)
|
log.error('插件关闭失败'.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.proxy.enabled) {
|
if (status.proxy.enabled) {
|
||||||
try {
|
try {
|
||||||
await proxy.close()
|
await proxy.close()
|
||||||
console.log('系统代理已关闭')
|
log.info('系统代理已关闭')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('系统代理关闭失败', err)
|
log.error('系统代理关闭失败', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status.server.enabled) {
|
if (status.server.enabled) {
|
||||||
try {
|
try {
|
||||||
await server.close()
|
await server.close()
|
||||||
console.log('代理服务已关闭')
|
log.info('代理服务已关闭')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('代理服务关闭失败', err)
|
log.error('代理服务关闭失败', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const expose = require('./expose.js')
|
const expose = require('./expose.js')
|
||||||
|
const log = require('./utils/util.log')
|
||||||
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
|
|
||||||
// 避免异常崩溃
|
// 避免异常崩溃
|
||||||
|
@ -8,11 +8,11 @@ process.on('uncaughtException', function (err) {
|
||||||
// console.error(err.errno)
|
// console.error(err.errno)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.error('uncaughtException', err)
|
log.error('uncaughtException', err)
|
||||||
})
|
})
|
||||||
|
|
||||||
process.on('unhandledRejection', (reason, p) => {
|
process.on('unhandledRejection', (reason, p) => {
|
||||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
|
log.error('Unhandled Rejection at: Promise', p, 'reason:', reason)
|
||||||
// application specific logging, throwing an error, or other logic here
|
// application specific logging, throwing an error, or other logic here
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
const nodeConfig = require('./config')
|
const nodeConfig = require('./config')
|
||||||
const NodePlugin = function (context) {
|
const NodePlugin = function (context) {
|
||||||
const { config, shell, event, rootCaFile } = context
|
const { config, shell, event, rootCaFile, log } = context
|
||||||
const nodeApi = {
|
const nodeApi = {
|
||||||
async start () {
|
async start () {
|
||||||
try {
|
try {
|
||||||
await nodeApi.setVariables()
|
await nodeApi.setVariables()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('set variables error', err)
|
log.warn('set variables error', err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ip = '127.0.0.1'
|
const ip = '127.0.0.1'
|
||||||
|
@ -123,7 +123,7 @@ const NodePlugin = function (context) {
|
||||||
await shell.setSystemEnv({ list: env })
|
await shell.setSystemEnv({ list: env })
|
||||||
}
|
}
|
||||||
event.fire('status', { key: 'plugin.node.enabled', value: true })
|
event.fire('status', { key: 'plugin.node.enabled', value: true })
|
||||||
console.info('开启【NPM】代理成功')
|
log.info('开启【NPM】代理成功')
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
},
|
},
|
||||||
|
@ -137,7 +137,7 @@ const NodePlugin = function (context) {
|
||||||
]
|
]
|
||||||
const ret = await shell.exec(cmds, { type: 'cmd' })
|
const ret = await shell.exec(cmds, { type: 'cmd' })
|
||||||
event.fire('status', { key: 'plugin.node.enabled', value: false })
|
event.fire('status', { key: 'plugin.node.enabled', value: false })
|
||||||
console.info('关闭【NPM】代理成功')
|
log.info('关闭【NPM】代理成功')
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const ProxyPlugin = function (context) {
|
const ProxyPlugin = function (context) {
|
||||||
const { config, event, shell } = context
|
const { config, event, shell, log } = context
|
||||||
const api = {
|
const api = {
|
||||||
async start () {
|
async start () {
|
||||||
return api.setProxy()
|
return api.setProxy()
|
||||||
|
@ -13,7 +13,7 @@ const ProxyPlugin = function (context) {
|
||||||
const ip = '127.0.0.1'
|
const ip = '127.0.0.1'
|
||||||
const port = config.get().server.port
|
const port = config.get().server.port
|
||||||
await shell.setSystemProxy({ ip, port })
|
await shell.setSystemProxy({ ip, port })
|
||||||
console.log(`开启系统代理成功:${ip}:${port}`)
|
log.info(`开启系统代理成功:${ip}:${port}`)
|
||||||
event.fire('status', { key: 'proxy.enabled', value: true })
|
event.fire('status', { key: 'proxy.enabled', value: true })
|
||||||
return { ip, port }
|
return { ip, port }
|
||||||
},
|
},
|
||||||
|
@ -22,10 +22,10 @@ const ProxyPlugin = function (context) {
|
||||||
try {
|
try {
|
||||||
await shell.setSystemProxy()
|
await shell.setSystemProxy()
|
||||||
event.fire('status', { key: 'proxy.enabled', vlaue: false })
|
event.fire('status', { key: 'proxy.enabled', vlaue: false })
|
||||||
console.log('关闭系统代理成功')
|
log.info('关闭系统代理成功')
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('关闭系统代理失败', err)
|
log.error('关闭系统代理失败', err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ const event = require('../../event')
|
||||||
const status = require('../../status')
|
const status = require('../../status')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const fork = require('child_process').fork
|
const fork = require('child_process').fork
|
||||||
|
const log = require('../../utils/util.log')
|
||||||
let server
|
let server
|
||||||
function fireStatus (status) {
|
function fireStatus (status) {
|
||||||
event.fire('status', { key: 'server.enabled', value: status })
|
event.fire('status', { key: 'server.enabled', value: status })
|
||||||
|
@ -53,7 +54,7 @@ const serverApi = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serverProcess.on('message', function (msg) {
|
serverProcess.on('message', function (msg) {
|
||||||
console.log('收到子进程消息', msg)
|
log.info('收到子进程消息', msg)
|
||||||
if (msg.type === 'status') {
|
if (msg.type === 'status') {
|
||||||
fireStatus(msg.event)
|
fireStatus(msg.event)
|
||||||
} else if (msg.type === 'error') {
|
} else if (msg.type === 'error') {
|
||||||
|
@ -81,21 +82,21 @@ const serverApi = {
|
||||||
// fireStatus('ing')// 关闭中
|
// fireStatus('ing')// 关闭中
|
||||||
server.close((err) => {
|
server.close((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('close error', err, ',', err.code, ',', err.message, ',', err.errno)
|
log.info('close error', err, ',', err.code, ',', err.message, ',', err.errno)
|
||||||
if (err.code === 'ERR_SERVER_NOT_RUNNING') {
|
if (err.code === 'ERR_SERVER_NOT_RUNNING') {
|
||||||
console.log('代理服务关闭成功')
|
log.info('代理服务关闭成功')
|
||||||
resolve()
|
resolve()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('代理服务关闭失败', err)
|
log.info('代理服务关闭失败', err)
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
console.log('代理服务关闭成功')
|
log.info('代理服务关闭成功')
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('server is null')
|
log.info('server is null')
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,7 +7,7 @@ const Registry = require('winreg')
|
||||||
// const cmd = require('node-cmd')
|
// const cmd = require('node-cmd')
|
||||||
const refreshInternetPs = require('./refresh-internet')
|
const refreshInternetPs = require('./refresh-internet')
|
||||||
const PowerShell = require('node-powershell')
|
const PowerShell = require('node-powershell')
|
||||||
|
const log = require('../../../utils/util.log')
|
||||||
const _lanIP = [
|
const _lanIP = [
|
||||||
'localhost',
|
'localhost',
|
||||||
'127.*',
|
'127.*',
|
||||||
|
@ -42,9 +42,9 @@ async function _winUnsetProxy (exec) {
|
||||||
_winAsyncRegSet(regKey, 'ProxyEnable', Registry.REG_DWORD, 0),
|
_winAsyncRegSet(regKey, 'ProxyEnable', Registry.REG_DWORD, 0),
|
||||||
_winAsyncRegSet(regKey, 'ProxyServer', Registry.REG_SZ, '')
|
_winAsyncRegSet(regKey, 'ProxyServer', Registry.REG_SZ, '')
|
||||||
])
|
])
|
||||||
console.log('代理关闭成功,等待refresh')
|
log.info('代理关闭成功,等待refresh')
|
||||||
await exec(refreshInternetPs, { type: 'ps' })
|
await exec(refreshInternetPs, { type: 'ps' })
|
||||||
console.log('代理关闭refresh完成')
|
log.info('代理关闭refresh完成')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ async function _winSetProxy (exec, ip, port) {
|
||||||
for (const string of _lanIP) {
|
for (const string of _lanIP) {
|
||||||
lanIpStr += string + ';'
|
lanIpStr += string + ';'
|
||||||
}
|
}
|
||||||
// console.log('lanIps:', lanIpStr, ip, port)
|
// log.info('lanIps:', lanIpStr, ip, port)
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
_winAsyncRegSet(regKey, 'MigrateProxy', Registry.REG_DWORD, 1),
|
_winAsyncRegSet(regKey, 'MigrateProxy', Registry.REG_DWORD, 1),
|
||||||
_winAsyncRegSet(regKey, 'ProxyEnable', Registry.REG_DWORD, 1),
|
_winAsyncRegSet(regKey, 'ProxyEnable', Registry.REG_DWORD, 1),
|
||||||
|
@ -66,9 +66,9 @@ async function _winSetProxy (exec, ip, port) {
|
||||||
_winAsyncRegSet(regKey, 'ProxyServer', Registry.REG_SZ, `${ip}:${port}`),
|
_winAsyncRegSet(regKey, 'ProxyServer', Registry.REG_SZ, `${ip}:${port}`),
|
||||||
_winAsyncRegSet(regKey, 'ProxyOverride', Registry.REG_SZ, lanIpStr)
|
_winAsyncRegSet(regKey, 'ProxyOverride', Registry.REG_SZ, lanIpStr)
|
||||||
])
|
])
|
||||||
console.log('代理设置成功,等待refresh')
|
log.info('代理设置成功,等待refresh')
|
||||||
await exec(refreshInternetPs)
|
await exec(refreshInternetPs)
|
||||||
console.log('代理设置refresh完成')
|
log.info('代理设置refresh完成')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,32 +84,16 @@ function _winAsyncRegSet (regKey, name, type, value) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _winResetWininetProxySettings (script) {
|
|
||||||
const ps = new PowerShell({
|
|
||||||
executionPolicy: 'Bypass',
|
|
||||||
noProfile: true
|
|
||||||
})
|
|
||||||
ps.addCommand(script)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const ret = await ps.invoke()
|
|
||||||
console.log('ps complete', script)
|
|
||||||
return ret
|
|
||||||
} finally {
|
|
||||||
ps.dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const executor = {
|
const executor = {
|
||||||
async windows (exec, params) {
|
async windows (exec, params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
// 清空代理
|
// 清空代理
|
||||||
console.log('关闭代理')
|
log.info('关闭代理')
|
||||||
return _winUnsetProxy(exec)
|
return _winUnsetProxy(exec)
|
||||||
} else {
|
} else {
|
||||||
// 设置代理
|
// 设置代理
|
||||||
const { ip, port } = params
|
const { ip, port } = params
|
||||||
console.log('设置代理', ip, port)
|
log.info('设置代理', ip, port)
|
||||||
return _winSetProxy(exec, ip, port)
|
return _winSetProxy(exec, ip, port)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ const childProcess = require('child_process')
|
||||||
const _exec = childProcess.exec
|
const _exec = childProcess.exec
|
||||||
const exec = util.promisify(_exec)
|
const exec = util.promisify(_exec)
|
||||||
const PowerShell = require('node-powershell')
|
const PowerShell = require('node-powershell')
|
||||||
|
const log = require('../utils/util.log')
|
||||||
class SystemShell {
|
class SystemShell {
|
||||||
static async exec (cmds, args) {
|
static async exec (cmds, args) {
|
||||||
throw new Error('You have to implement the method exec!')
|
throw new Error('You have to implement the method exec!')
|
||||||
|
@ -52,7 +52,7 @@ class WindowsSystemShell extends SystemShell {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ret = await ps.invoke()
|
const ret = await ps.invoke()
|
||||||
// console.log('ps complete', cmds)
|
// log.info('ps complete', cmds)
|
||||||
return ret
|
return ret
|
||||||
} finally {
|
} finally {
|
||||||
ps.dispose()
|
ps.dispose()
|
||||||
|
@ -64,7 +64,7 @@ class WindowsSystemShell extends SystemShell {
|
||||||
}
|
}
|
||||||
// compose += '&& exit'
|
// compose += '&& exit'
|
||||||
const ret = await childExec(compose)
|
const ret = await childExec(compose)
|
||||||
// console.log('cmd complete:', compose)
|
// log.info('cmd complete:', compose)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,13 +75,13 @@ function childExec (composeCmds) {
|
||||||
const childProcess = require('child_process')
|
const childProcess = require('child_process')
|
||||||
childProcess.exec(composeCmds, function (error, stdout, stderr) {
|
childProcess.exec(composeCmds, function (error, stdout, stderr) {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('cmd 命令执行错误:', composeCmds, error, stderr)
|
log.error('cmd 命令执行错误:', composeCmds, error, stderr)
|
||||||
reject(error)
|
reject(error)
|
||||||
} else {
|
} else {
|
||||||
// console.log('cmd 命令完成:', stdout)
|
// log.info('cmd 命令完成:', stdout)
|
||||||
resolve(stdout)
|
resolve(stdout)
|
||||||
}
|
}
|
||||||
// console.log('关闭 cmd')
|
// log.info('关闭 cmd')
|
||||||
// ps.kill('SIGINT')
|
// ps.kill('SIGINT')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const event = require('./event')
|
const event = require('./event')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
|
const log = require('./utils/util.log')
|
||||||
const status = {
|
const status = {
|
||||||
server: { enabled: false },
|
server: { enabled: false },
|
||||||
proxy: {},
|
proxy: {},
|
||||||
|
@ -8,7 +9,7 @@ const status = {
|
||||||
|
|
||||||
event.register('status', (event) => {
|
event.register('status', (event) => {
|
||||||
lodash.set(status, event.key, event.value)
|
lodash.set(status, event.key, event.value)
|
||||||
console.log('status changed:', event)
|
log.info('status changed:', event)
|
||||||
}, -999)
|
}, -999)
|
||||||
|
|
||||||
module.exports = status
|
module.exports = status
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
const os = require('os')
|
|
||||||
module.exports = {
|
|
||||||
isWindows7 () {
|
|
||||||
const version = os.release()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
const os = require('os')
|
|
||||||
const util = {
|
|
||||||
getNodeVersion () {
|
|
||||||
const version = process.version
|
|
||||||
console.log(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
util.getNodeVersion()
|
|
||||||
module.exports = util
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
const log4js = require('log4js')
|
||||||
|
const path = require('path')
|
||||||
|
const getDefaultConfigBasePath = function () {
|
||||||
|
const userHome = process.env.HOME || process.env.USERPROFILE
|
||||||
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
|
}
|
||||||
|
log4js.configure({
|
||||||
|
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: '.yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/server.log' } },
|
||||||
|
categories: { default: { appenders: ['file', 'std'], level: 'info' } }
|
||||||
|
})
|
||||||
|
const logger = log4js.getLogger('server')
|
||||||
|
module.exports = logger
|
|
@ -14,6 +14,7 @@
|
||||||
},
|
},
|
||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"log4js": "^6.3.0",
|
||||||
"@docmirror/dev-sidecar": "^1.1.0",
|
"@docmirror/dev-sidecar": "^1.1.0",
|
||||||
"@docmirror/mitmproxy": "^1.1.0",
|
"@docmirror/mitmproxy": "^1.1.0",
|
||||||
"ant-design-vue": "^1.6.5",
|
"ant-design-vue": "^1.6.5",
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
||||||
import bridge from './bridge/index'
|
import bridge from './bridge/index'
|
||||||
import updateHandle from './bridge/update-handle'
|
import updateHandle from './bridge/update-handle'
|
||||||
import { ebtMain } from './tongji'
|
import { ebtMain } from './tongji'
|
||||||
|
import log from './utils/util.log'
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const isMac = process.platform === 'darwin'
|
const isMac = process.platform === 'darwin'
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ function setTray (app) {
|
||||||
// appTray.setContextMenu(contextMenu)
|
// appTray.setContextMenu(contextMenu)
|
||||||
|
|
||||||
// appTray.on('double-click', function () {
|
// appTray.on('double-click', function () {
|
||||||
// console.log('double click')
|
// log.info('double click')
|
||||||
// win.show()
|
// win.show()
|
||||||
// })
|
// })
|
||||||
appTray.on('right-click', function (event, bounds) {
|
appTray.on('right-click', function (event, bounds) {
|
||||||
|
@ -122,13 +122,13 @@ app.disableHardwareAcceleration() // 禁用gpu
|
||||||
// 禁止双开
|
// 禁止双开
|
||||||
const isFirstInstance = app.requestSingleInstanceLock()
|
const isFirstInstance = app.requestSingleInstanceLock()
|
||||||
if (!isFirstInstance) {
|
if (!isFirstInstance) {
|
||||||
console.log('is second instance')
|
log.info('is second instance')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
app.quit()
|
app.quit()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} else {
|
} else {
|
||||||
app.on('before-quit', async (event) => {
|
app.on('before-quit', async (event) => {
|
||||||
console.log('before-quit')
|
log.info('before-quit')
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
// if (tray) {
|
// if (tray) {
|
||||||
// tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' })
|
// tray.displayBalloon({ title: '正在关闭,请稍候...', content: '正在关闭中,请稍候。。。' })
|
||||||
|
@ -137,7 +137,7 @@ if (!isFirstInstance) {
|
||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||||
console.log('new app started', commandLine)
|
log.info('new app started', commandLine)
|
||||||
if (win) {
|
if (win) {
|
||||||
win.show()
|
win.show()
|
||||||
win.focus()
|
win.focus()
|
||||||
|
@ -170,7 +170,7 @@ if (!isFirstInstance) {
|
||||||
// try {
|
// try {
|
||||||
// await installExtension(VUEJS_DEVTOOLS)
|
// await installExtension(VUEJS_DEVTOOLS)
|
||||||
// } catch (e) {
|
// } catch (e) {
|
||||||
// console.error('Vue Devtools failed to install:', e.toString())
|
// log.error('Vue Devtools failed to install:', e.toString())
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
createWindow()
|
createWindow()
|
||||||
|
@ -196,7 +196,7 @@ if (!isFirstInstance) {
|
||||||
// 最小化到托盘
|
// 最小化到托盘
|
||||||
tray = setTray(app)
|
tray = setTray(app)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('err', err)
|
log.info('err', err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import JSON5 from 'json5'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
const pk = require('../../package.json')
|
const pk = require('../../package.json')
|
||||||
const mitmproxyPath = path.join(__dirname, 'mitmproxy.js')
|
const mitmproxyPath = path.join(__dirname, 'mitmproxy.js')
|
||||||
|
const log = require('../utils/util.log')
|
||||||
const getDefaultConfigBasePath = function () {
|
const getDefaultConfigBasePath = function () {
|
||||||
const userHome = process.env.HOME || process.env.USERPROFILE
|
const userHome = process.env.HOME || process.env.USERPROFILE
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
|
@ -22,12 +22,12 @@ const localApi = {
|
||||||
lodash.merge(core, local)
|
lodash.merge(core, local)
|
||||||
const list = []
|
const list = []
|
||||||
_deepFindFunction(list, core, '')
|
_deepFindFunction(list, core, '')
|
||||||
// console.log('api list:', list)
|
// log.info('api list:', list)
|
||||||
return list
|
return list
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
get () {
|
get () {
|
||||||
console.log(pk)
|
log.info(pk)
|
||||||
return {
|
return {
|
||||||
version: pk.version
|
version: pk.version
|
||||||
}
|
}
|
||||||
|
@ -182,23 +182,23 @@ export default {
|
||||||
target = lodash.get(DevSidecar.api, api)
|
target = lodash.get(DevSidecar.api, api)
|
||||||
}
|
}
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
console.log('找不到此接口方法:', api)
|
log.info('找不到此接口方法:', api)
|
||||||
}
|
}
|
||||||
let param
|
let param
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
param = args[1]
|
param = args[1]
|
||||||
}
|
}
|
||||||
const ret = target(param)
|
const ret = target(param)
|
||||||
// console.log('api:', api, 'ret:', ret)
|
// log.info('api:', api, 'ret:', ret)
|
||||||
return ret
|
return ret
|
||||||
})
|
})
|
||||||
// 注册从core里来的事件,并转发给view
|
// 注册从core里来的事件,并转发给view
|
||||||
DevSidecar.api.event.register('status', (event) => {
|
DevSidecar.api.event.register('status', (event) => {
|
||||||
console.log('bridge on status', event)
|
log.info('bridge on status', event)
|
||||||
win.webContents.send('status', { ...event })
|
win.webContents.send('status', { ...event })
|
||||||
})
|
})
|
||||||
DevSidecar.api.event.register('error', (event) => {
|
DevSidecar.api.event.register('error', (event) => {
|
||||||
console.error('bridge on error', event)
|
log.error('bridge on error', event)
|
||||||
win.webContents.send('error.core', event)
|
win.webContents.send('error.core', event)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { ipcMain, dialog } from 'electron'
|
import { ipcMain, dialog } from 'electron'
|
||||||
import { autoUpdater } from 'electron-updater'
|
import { autoUpdater } from 'electron-updater'
|
||||||
|
import log from '../utils/util.log'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
// win是所有窗口的引用
|
// win是所有窗口的引用
|
||||||
// const path = require('path') // 引入path模块
|
// const path = require('path') // 引入path模块
|
||||||
|
@ -31,30 +32,30 @@ function updateHandle (win, updateUrl) {
|
||||||
url: updateUrl
|
url: updateUrl
|
||||||
})
|
})
|
||||||
autoUpdater.on('error', function (error) {
|
autoUpdater.on('error', function (error) {
|
||||||
console.log('autoUpdater error', error)
|
log.info('autoUpdater error', error)
|
||||||
sendUpdateMessage({ key: 'error', value: error, error: error })
|
sendUpdateMessage({ key: 'error', value: error, error: error })
|
||||||
// dialog.showErrorBox('Error: ', error == null ? 'unknown' : (error.stack || error).toString())
|
// dialog.showErrorBox('Error: ', error == null ? 'unknown' : (error.stack || error).toString())
|
||||||
})
|
})
|
||||||
autoUpdater.on('checking-for-update', function () {
|
autoUpdater.on('checking-for-update', function () {
|
||||||
console.log('autoUpdater checking-for-update')
|
log.info('autoUpdater checking-for-update')
|
||||||
sendUpdateMessage({ key: 'checking', value: message.checking })
|
sendUpdateMessage({ key: 'checking', value: message.checking })
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-available', function (info) {
|
autoUpdater.on('update-available', function (info) {
|
||||||
console.log('autoUpdater update-available')
|
log.info('autoUpdater update-available')
|
||||||
sendUpdateMessage({ key: 'available', value: info })
|
sendUpdateMessage({ key: 'available', value: info })
|
||||||
})
|
})
|
||||||
autoUpdater.on('update-not-available', function (info) {
|
autoUpdater.on('update-not-available', function (info) {
|
||||||
console.log('autoUpdater update-not-available')
|
log.info('autoUpdater update-not-available')
|
||||||
sendUpdateMessage({ key: 'notAvailable', value: message.updateNotAva })
|
sendUpdateMessage({ key: 'notAvailable', value: message.updateNotAva })
|
||||||
})
|
})
|
||||||
// 更新下载进度
|
// 更新下载进度
|
||||||
autoUpdater.on('download-progress', function (progressObj) {
|
autoUpdater.on('download-progress', function (progressObj) {
|
||||||
console.log('autoUpdater download-progress')
|
log.info('autoUpdater download-progress')
|
||||||
win.webContents.send('update', { key: 'progress', value: parseInt(progressObj.percent) })
|
win.webContents.send('update', { key: 'progress', value: parseInt(progressObj.percent) })
|
||||||
})
|
})
|
||||||
// 更新完成,重启应用
|
// 更新完成,重启应用
|
||||||
autoUpdater.on('update-downloaded', function (info) {
|
autoUpdater.on('update-downloaded', function (info) {
|
||||||
console.log('download complete', info.version)
|
log.info('download complete', info.version)
|
||||||
win.webContents.send('update', {
|
win.webContents.send('update', {
|
||||||
key: 'downloaded',
|
key: 'downloaded',
|
||||||
value: {
|
value: {
|
||||||
|
@ -70,21 +71,21 @@ function updateHandle (win, updateUrl) {
|
||||||
autoUpdater.quitAndInstall()
|
autoUpdater.quitAndInstall()
|
||||||
} else if (arg.key === 'checkForUpdate') {
|
} else if (arg.key === 'checkForUpdate') {
|
||||||
// 执行自动更新检查
|
// 执行自动更新检查
|
||||||
console.log('autoUpdater checkForUpdates')
|
log.info('autoUpdater checkForUpdates')
|
||||||
autoUpdater.checkForUpdates()
|
autoUpdater.checkForUpdates()
|
||||||
} else if (arg.key === 'downloadUpdate') {
|
} else if (arg.key === 'downloadUpdate') {
|
||||||
// 下载新版本
|
// 下载新版本
|
||||||
console.log('autoUpdater downloadUpdate')
|
log.info('autoUpdater downloadUpdate')
|
||||||
autoUpdater.downloadUpdate()
|
autoUpdater.downloadUpdate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 通过main进程发送事件给renderer进程,提示更新信息
|
// 通过main进程发送事件给renderer进程,提示更新信息
|
||||||
function sendUpdateMessage (message) {
|
function sendUpdateMessage (message) {
|
||||||
console.log('autoUpdater sendUpdateMessage')
|
log.info('autoUpdater sendUpdateMessage')
|
||||||
win.webContents.send('update', message)
|
win.webContents.send('update', message)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('auto update inited')
|
log.info('auto update inited')
|
||||||
return autoUpdater
|
return autoUpdater
|
||||||
}
|
}
|
||||||
export default updateHandle
|
export default updateHandle
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
const log4js = require('log4js')
|
||||||
|
const path = require('path')
|
||||||
|
const getDefaultConfigBasePath = function () {
|
||||||
|
const userHome = process.env.HOME || process.env.USERPROFILE
|
||||||
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
|
}
|
||||||
|
log4js.configure({
|
||||||
|
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: '.yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/server.log' } },
|
||||||
|
categories: { default: { appenders: ['file', 'std'], level: 'info' } }
|
||||||
|
})
|
||||||
|
const logger = log4js.getLogger('server')
|
||||||
|
module.exports = logger
|
Loading…
Reference in New Issue