diff --git a/packages/gui/babel.config.js b/packages/gui/babel.config.js index e955840..df19538 100644 --- a/packages/gui/babel.config.js +++ b/packages/gui/babel.config.js @@ -1,5 +1,5 @@ module.exports = { presets: [ - '@vue/cli-plugin-babel/preset' - ] + '@vue/cli-plugin-babel/preset', + ], } diff --git a/packages/gui/pkg/after-all-artifact-build.js b/packages/gui/pkg/after-all-artifact-build.js index e821c4c..9c61f50 100644 --- a/packages/gui/pkg/after-all-artifact-build.js +++ b/packages/gui/pkg/after-all-artifact-build.js @@ -1,6 +1,6 @@ +const fs = require('fs') const path = require('path') const pkg = require('../package.json') -const fs = require('fs') function appendIntro (context, systemType, latest) { const version = pkg.version @@ -14,8 +14,7 @@ partMiniVersion: 1.7.0 releaseNotes: - 升级日志 - https://download.fastgit.org/docmirror/dev-sidecar/releases/download/v${version}/DevSidecar-${version}.exe -`, - (err) => { +`, (err) => { if (err) { console.log('修改latest 失败') } diff --git a/packages/gui/pkg/after-pack.js b/packages/gui/pkg/after-pack.js index d312c9c..4855117 100644 --- a/packages/gui/pkg/after-pack.js +++ b/packages/gui/pkg/after-pack.js @@ -1,7 +1,7 @@ +const fs = require('fs') const path = require('path') const AdmZip = require('adm-zip') const pkg = require('../package.json') -const fs = require('fs') function writeAppUpdateYmlForLinux () { const publishUrl = process.env.VUE_APP_PUBLISH_URL diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index b572d6c..8a88442 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -1,17 +1,15 @@ 'use strict' /* global __static */ import path from 'path' -import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, powerMonitor, nativeImage, nativeTheme, globalShortcut } from 'electron' +import DevSidecar from '@docmirror/dev-sidecar' +import { app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, nativeImage, nativeTheme, powerMonitor, protocol, Tray } from 'electron' +import minimist from 'minimist' import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' import backend from './bridge/backend' -import DevSidecar from '@docmirror/dev-sidecar' import log from './utils/util.log' -import minimist from 'minimist' const isWindows = process.platform === 'win32' -// eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' -// import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer' const isDevelopment = process.env.NODE_ENV !== 'production' // 避免其他系统出现异常,只有 Windows 使用 './background/powerMonitor' @@ -21,14 +19,13 @@ const _powerMonitor = isWindows ? require('./background/powerMonitor').powerMoni // be closed automatically when the JavaScript object is garbage collected. let win let winIsHidden = false -// eslint-disable-next-line no-unused-vars let tray // 防止被内存清理 let forceClose = false DevSidecar.api.config.reload() let hideDockWhenWinClose = DevSidecar.api.config.get().app.dock.hideWhenWinClose || false // Scheme must be registered before the app is ready protocol.registerSchemesAsPrivileged([ - { scheme: 'app', privileges: { secure: true, standard: true } } + { scheme: 'app', privileges: { secure: true, standard: true } }, ]) function openDevTools () { @@ -73,7 +70,7 @@ function setTray () { { // 系统托盘图标目录 label: 'DevTools (F12)', - click: switchDevTools + click: switchDevTools, }, { // 系统托盘图标目录 @@ -82,8 +79,8 @@ function setTray () { log.info('force quit') forceClose = true quit() - } - } + }, + }, ] // 设置系统托盘图标 const iconRootPath = path.join(__dirname, '../extra/icons/tray') @@ -123,8 +120,8 @@ function setTray () { showWin() }) - appTray.on('right-click', function () { - setTimeout(function () { + appTray.on('right-click', () => { + setTimeout(() => { appTray.popUpContextMenu(contextMenu) }, 200) }) @@ -181,11 +178,10 @@ function createWindow (startHideWindow) { // preload: path.join(__dirname, 'preload.js'), // Use pluginOptions.nodeIntegration, leave this alone // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info - nodeIntegration: true// process.env.ELECTRON_NODE_INTEGRATION + nodeIntegration: true, // process.env.ELECTRON_NODE_INTEGRATION }, show: !startHideWindow, - // eslint-disable-next-line no-undef - icon: path.join(__static, 'icon.png') + icon: path.join(__static, 'icon.png'), }) winIsHidden = !!startHideWindow @@ -263,7 +259,6 @@ function createWindow (startHideWindow) { event.preventDefault() // 切换开发者工具显示状态 switchDevTools() - // eslint-disable-next-line brace-style } // 按 F5,刷新页面 else if (input.key === 'F5') { @@ -368,7 +363,7 @@ if (app.getLoginItemSettings().wasOpenedAsHidden) { log.info('start args:', args) // 通过启动参数,判断是否隐藏窗口 - const hideWindowArg = args.hideWindow + '' + const hideWindowArg = `${args.hideWindow}` if (hideWindowArg === 'true' || hideWindowArg === '1') { startHideWindow = true } else if (hideWindowArg === 'false' || hideWindowArg === '0') { @@ -483,7 +478,7 @@ if (isDevelopment) { } } // 系统关机和重启时的操作 -process.on('exit', function () { +process.on('exit', () => { log.info('进程结束,退出app') quit() }) diff --git a/packages/gui/src/background/powerMonitor.js b/packages/gui/src/background/powerMonitor.js index dd8b9ac..3431fe6 100644 --- a/packages/gui/src/background/powerMonitor.js +++ b/packages/gui/src/background/powerMonitor.js @@ -1,5 +1,5 @@ +import { acquireShutdownBlock, insertWndProcHook, releaseShutdownBlock, removeWndProcHook, setMainWindowHandle } from '@natmri/platform-napi' import { powerMonitor as _powerMonitor } from 'electron' -import { setMainWindowHandle, insertWndProcHook, removeWndProcHook, releaseShutdownBlock, acquireShutdownBlock } from '@natmri/platform-napi' class PowerMonitor { constructor () { @@ -43,7 +43,7 @@ class PowerMonitor { if (event === 'shutdown' && process.platform === 'win32') { if (!this._shutdownCallback) { this._shutdownCallback = async () => { - await Promise.all(this._listeners.map((fn) => fn())) + await Promise.all(this._listeners.map(fn => fn())) releaseShutdownBlock() } insertWndProcHook(this._shutdownCallback) @@ -57,7 +57,7 @@ class PowerMonitor { off (event, listener) { if (event === 'shutdown' && process.platform === 'win32') { - this._listeners = this._listeners.filter((fn) => fn !== listener) + this._listeners = this._listeners.filter(fn => fn !== listener) } else { return _powerMonitor.off(event, listener) } diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js index d1d3ab2..6697e8b 100644 --- a/packages/gui/src/bridge/api/backend.js +++ b/packages/gui/src/bridge/api/backend.js @@ -1,14 +1,16 @@ -import lodash from 'lodash' -import DevSidecar from '@docmirror/dev-sidecar' -import { ipcMain } from 'electron' import fs from 'fs' import path from 'path' +import DevSidecar from '@docmirror/dev-sidecar' +import { ipcMain } from 'electron' +import lodash from 'lodash' + const pk = require('../../../package.json') -const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') -process.env.DS_EXTRA_PATH = path.join(__dirname, '../extra/') const jsonApi = require('@docmirror/mitmproxy/src/json') const log = require('../../utils/util.log') +const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') +process.env.DS_EXTRA_PATH = path.join(__dirname, '../extra/') + const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath } @@ -42,7 +44,7 @@ const localApi = { info: { get () { return { - version: pk.version + version: pk.version, } }, getConfigDir () { @@ -50,7 +52,7 @@ const localApi = { }, getSystemPlatform () { return DevSidecar.api.shell.getSystemPlatform() - } + }, }, /** * 软件设置 @@ -83,7 +85,7 @@ const localApi = { if (setting.rootCa == null) { setting.rootCa = { setuped: false, - desc: '根证书未安装' + desc: '根证书未安装', } } @@ -96,7 +98,7 @@ const localApi = { const settingPath = _getSettingsPath() fs.writeFileSync(settingPath, jsonApi.stringify(setting)) log.info('保存 setting.json 配置文件成功:', settingPath) - } + }, }, /** * 启动所有 @@ -119,8 +121,8 @@ const localApi = { */ restart () { return DevSidecar.api.server.restart({ mitmproxyPath }) - } - } + }, + }, } function _deepFindFunction (list, parent, parentKey) { @@ -129,7 +131,7 @@ function _deepFindFunction (list, parent, parentKey) { if (item instanceof Function) { list.push(parentKey + key) } else if (item instanceof Object) { - _deepFindFunction(list, item, parentKey + key + '.') + _deepFindFunction(list, item, `${parentKey + key}.`) } } } @@ -184,14 +186,20 @@ export default { // 注册从core里来的事件,并转发给view DevSidecar.api.event.register('status', (event) => { log.info('bridge on status, event:', event) - if (win) win.webContents.send('status', { ...event }) + if (win) { + win.webContents.send('status', { ...event }) + } }) DevSidecar.api.event.register('error', (event) => { log.error('bridge on error, event:', event) - if (win) win.webContents.send('error.core', event) + if (win) { + win.webContents.send('error.core', event) + } }) DevSidecar.api.event.register('speed', (event) => { - if (win) win.webContents.send('speed', event) + if (win) { + win.webContents.send('speed', event) + } }) // 合并用户配置 @@ -200,5 +208,5 @@ export default { }, devSidecar: DevSidecar, invoke, - getDateTimeStr + getDateTimeStr, } diff --git a/packages/gui/src/bridge/api/open-enable-loopback.js b/packages/gui/src/bridge/api/open-enable-loopback.js index 666aa8d..a669643 100644 --- a/packages/gui/src/bridge/api/open-enable-loopback.js +++ b/packages/gui/src/bridge/api/open-enable-loopback.js @@ -1,12 +1,14 @@ -import Sudoer from 'electron-sudo' import DevSidecar from '@docmirror/dev-sidecar' +import Sudoer from 'electron-sudo' + export default { async open () { const options = { name: '设置loopback' } const sudoer = new Sudoer(options) const exeFile = DevSidecar.api.shell.extraPath.getEnableLoopbackPath() await sudoer.exec( - exeFile, { env: { PARAM: 'VALUE' } } + exeFile, + { env: { PARAM: 'VALUE' } }, ) - } + }, } diff --git a/packages/gui/src/bridge/auto-start/backend.js b/packages/gui/src/bridge/auto-start/backend.js index d86b577..fed4d26 100644 --- a/packages/gui/src/bridge/auto-start/backend.js +++ b/packages/gui/src/bridge/auto-start/backend.js @@ -44,8 +44,9 @@ export default { openAtLogin: true, openAsHidden: true, args: [ - '--hideWindow', '"true"' - ] + '--hideWindow', + '"true"', + ], }) } @@ -57,12 +58,12 @@ export default { app.setLoginItemSettings({ openAtLogin: false, openAsHidden: false, - args: [] + args: [], }) } event.sender.send('auto-start', { key: 'enabled', value: false }) } }) - } + }, } diff --git a/packages/gui/src/bridge/auto-start/front.js b/packages/gui/src/bridge/auto-start/front.js index 2e1a4f2..4d19525 100644 --- a/packages/gui/src/bridge/auto-start/front.js +++ b/packages/gui/src/bridge/auto-start/front.js @@ -1,4 +1,3 @@ - function install (app, api) { api.ipc.on('auto-start', (event, message) => { if (message.value === true) { @@ -10,10 +9,10 @@ function install (app, api) { api.autoStart = { async enabled (value) { api.ipc.send('auto-start', { key: 'enabled', value }) - } + }, } } export default { - install + install, } diff --git a/packages/gui/src/bridge/backend.js b/packages/gui/src/bridge/backend.js index 78e262c..404b11c 100644 --- a/packages/gui/src/bridge/backend.js +++ b/packages/gui/src/bridge/backend.js @@ -1,15 +1,15 @@ import api from './api/backend' +import autoStart from './auto-start/backend' +import fileSelector from './file-selector/backend' import tongji from './tongji/backend' import update from './update/backend' -import fileSelector from './file-selector/backend' -import autoStart from './auto-start/backend' const modules = { api, // 核心接口模块 fileSelector, // 文件选择模块 tongji, // 统计模块 update, // 自动更新 - autoStart + autoStart, } export default { install (context) { @@ -18,5 +18,5 @@ export default { modules[module].install(context) } }, - ...modules + ...modules, } diff --git a/packages/gui/src/bridge/error/front.js b/packages/gui/src/bridge/error/front.js index fbf2061..abb835f 100644 --- a/packages/gui/src/bridge/error/front.js +++ b/packages/gui/src/bridge/error/front.js @@ -13,28 +13,27 @@ function install (app, api) { function handleServerStartError (message, err, app, api) { if (message.value === 'EADDRINUSE') { - // eslint-disable-next-line no-debugger app.$confirm({ title: '端口被占用,代理服务启动失败', content: '是否要杀掉占用进程?您也可以点击取消,然后前往加速服务->基本设置中修改代理端口', onOk () { // TODO 杀掉进程 - api.config.get().then(config => { + api.config.get().then((config) => { console.log('config', config) - api.shell.killByPort({ port: config.server.port }).then(ret => { + api.shell.killByPort({ port: config.server.port }).then((ret) => { app.$message.info('杀掉进程成功,请重试开启代理服务') }) }) }, onCancel () { console.log('Cancel') - } + }, }) } else { - app.$message.error('加速服务启动失败:' + message.message) + app.$message.error(`加速服务启动失败:${message.message}`) } } export default { - install + install, } diff --git a/packages/gui/src/bridge/file-selector/backend.js b/packages/gui/src/bridge/file-selector/backend.js index 3acba92..6cdec45 100644 --- a/packages/gui/src/bridge/file-selector/backend.js +++ b/packages/gui/src/bridge/file-selector/backend.js @@ -1,21 +1,21 @@ export default { install (context) { const { ipcMain, dialog, log } = context - ipcMain.on('file-selector', function (event, message) { + ipcMain.on('file-selector', (event, message) => { if (message.key === 'open') { dialog.showOpenDialog({ properties: ['openFile'], - ...message - }).then(result => { + ...message, + }).then((result) => { if (result.canceled) { event.sender.send('file-selector', { key: 'canceled' }) } else { event.sender.send('file-selector', { key: 'selected', value: result.filePaths }) } - }).catch(err => { + }).catch((err) => { log.error('选择文件失败:', err) }) } }) - } + }, } diff --git a/packages/gui/src/bridge/file-selector/front.js b/packages/gui/src/bridge/file-selector/front.js index 284cdce..69b0d31 100644 --- a/packages/gui/src/bridge/file-selector/front.js +++ b/packages/gui/src/bridge/file-selector/front.js @@ -1,9 +1,8 @@ - function install (app, api) { api.fileSelector = { open (value, options) { return new Promise((resolve, reject) => { - api.ipc.send('file-selector', { key: 'open', value: value, ...options }) + api.ipc.send('file-selector', { key: 'open', value, ...options }) api.ipc.on('file-selector', (event, message) => { console.log('selector', message) if (message.key === 'selected') { @@ -14,10 +13,10 @@ function install (app, api) { api.ipc.on('file-selector', () => {}) }) }) - } + }, } } export default { - install + install, } diff --git a/packages/gui/src/bridge/front.js b/packages/gui/src/bridge/front.js index 7224a30..8e6f51d 100644 --- a/packages/gui/src/bridge/front.js +++ b/packages/gui/src/bridge/front.js @@ -1,10 +1,11 @@ +import autoStart from './auto-start/front' // import api from './api/front' import error from './error/front' -import tongji from './tongji/front' -import update from './update/front' import fileSelector from './file-selector/front' -import autoStart from './auto-start/front' import onClose from './on-close/front' +import tongji from './tongji/front' +import update from './update/front' + const modules = { // api, // 核心接口模块 error, @@ -12,7 +13,7 @@ const modules = { tongji, // 统计模块 update, // 自动更新 autoStart, - onClose + onClose, } export default { install (app, api, router) { @@ -20,5 +21,5 @@ export default { modules[module].install(app, api, router) } }, - ...modules + ...modules, } diff --git a/packages/gui/src/bridge/mitmproxy.js b/packages/gui/src/bridge/mitmproxy.js index 590829a..5590874 100644 --- a/packages/gui/src/bridge/mitmproxy.js +++ b/packages/gui/src/bridge/mitmproxy.js @@ -1,10 +1,10 @@ -// eslint-disable-next-line no-unused-vars -const log = require('../utils/util.log') +const fs = require('fs') +const path = require('path') const server = require('@docmirror/mitmproxy') const jsonApi = require('@docmirror/mitmproxy/src/json') +const log = require('../utils/util.log') + const configPath = process.argv[2] -const fs = require('fs') -const path = require('path') const configJson = fs.readFileSync(configPath) log.info('读取 running.json by gui bridge 成功:', configPath) const config = jsonApi.parse(configJson.toString()) diff --git a/packages/gui/src/bridge/on-close/front.js b/packages/gui/src/bridge/on-close/front.js index 1a14fdb..7c8e871 100644 --- a/packages/gui/src/bridge/on-close/front.js +++ b/packages/gui/src/bridge/on-close/front.js @@ -12,19 +12,21 @@ function install (app, api) { } app.$confirm({ title: '关闭策略', - content: h =>
-
- - 直接关闭 - 最小化到系统托盘 - + content: h => ( +
+
+ + 直接关闭 + 最小化到系统托盘 + +
+
+ + 记住本次选择,不再提示 + +
-
- - 记住本次选择,不再提示 - < /a-checkbox> -
-
, + ), async onOk () { console.log('OK. closeType=', closeType) if (doSave) { @@ -34,11 +36,11 @@ function install (app, api) { }, onCancel () { console.log('Cancel. closeType=', closeType) - } + }, }) }) } export default { - install + install, } diff --git a/packages/gui/src/bridge/tongji/backend.js b/packages/gui/src/bridge/tongji/backend.js index 294badb..78d399f 100644 --- a/packages/gui/src/bridge/tongji/backend.js +++ b/packages/gui/src/bridge/tongji/backend.js @@ -1,9 +1,8 @@ - /** * first step * @param {*} ipcMain */ -const ebtMain = (ipcMain) => { +function ebtMain (ipcMain) { const isDevelopment = process.env.NODE_ENV !== 'production' const request = require('request') /* istanbul ignore else */ @@ -19,17 +18,16 @@ const ebtMain = (ipcMain) => { url: `https://hm.baidu.com/hm.js?${arg}`, method: 'GET', headers: { - Referer: 'https://hm.baidu.com/' - } - }, - (err, response, body) => { + Referer: 'https://hm.baidu.com/', + }, + }, (err, response, body) => { if (err) { console.error('百度统计请求出错', err) return } const rource = '(h.c.b.su=h.c.b.u||document.location.href),h.c.b.u=f.protocol+"//"+document.location.host+' /* istanbul ignore else */ - if (body && body.indexOf(rource) >= 0) { + if (body && body.includes(rource)) { // step 3 let text = body @@ -51,5 +49,5 @@ const ebtMain = (ipcMain) => { export default { install (context) { ebtMain(context.ipcMain) - } + }, } diff --git a/packages/gui/src/bridge/tongji/front.js b/packages/gui/src/bridge/tongji/front.js index 023db8b..53cdf37 100644 --- a/packages/gui/src/bridge/tongji/front.js +++ b/packages/gui/src/bridge/tongji/front.js @@ -1,11 +1,10 @@ - /** * second step * @param {*} ipcRenderer * @param {*} siteId * @param {*} router */ -const ebtRenderer = (ipcRenderer, siteId, router) => { +function ebtRenderer (ipcRenderer, siteId, router) { /* istanbul ignore else */ if (!(ipcRenderer && ipcRenderer.on && ipcRenderer.send)) { throw new TypeError('require ipcRenderer') @@ -38,7 +37,7 @@ const ebtRenderer = (ipcRenderer, siteId, router) => { router.beforeEach((to, _, next) => { /* istanbul ignore else */ if (to.path) { - window._hmt.push(['_trackPageview', '/#' + to.fullPath]) + window._hmt.push(['_trackPageview', `/#${to.fullPath}`]) console.log('baidu trace', to.fullPath) } @@ -58,5 +57,5 @@ export default { const { ipcRenderer } = require('electron') ebtRenderer(ipcRenderer, BAIDU_SITE_ID, router) }, - ebtRenderer + ebtRenderer, } diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index 6847d08..32e0f02 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -1,16 +1,15 @@ +import fs from 'fs' +import path from 'path' +import DevSidecar from '@docmirror/dev-sidecar' +import AdmZip from 'adm-zip' import { ipcMain } from 'electron' import { autoUpdater } from 'electron-updater' -import path from 'path' import request from 'request' import progress from 'request-progress' -import fs from 'fs' -import AdmZip from 'adm-zip' -import log from '../../utils/util.log' -import appPathUtil from '../../utils/util.apppath' import pkg from '../../../package.json' -import DevSidecar from '@docmirror/dev-sidecar' +import appPathUtil from '../../utils/util.apppath' +import log from '../../utils/util.log' -// eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' const isLinux = process.platform === 'linux' @@ -24,16 +23,16 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { // delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms // lengthHeader: 'x-transfer-length' // Length header to use, defaults to content-length }) - .on('progress', function (state) { + .on('progress', (state) => { onProgress(state.percent * 100) log.log('progress', state.percent) }) - .on('error', function (err) { + .on('error', (err) => { // Do something with err log.error('下载升级包失败:', err) onError(err) }) - .on('end', function () { + .on('end', () => { // Do something after request finishes onSuccess() }) @@ -44,10 +43,10 @@ function parseVersion (version) { const matched = version.match(/^v?(\d+\.\d+\.\d+)(.*)$/) const versionArr = matched[1].split('.') return { - major: parseInt(versionArr[0]), - minor: parseInt(versionArr[1]), - patch: parseInt(versionArr[2]), - suffix: matched[2] + major: Number.parseInt(versionArr[0]), + minor: Number.parseInt(versionArr[1]), + patch: Number.parseInt(versionArr[2]), + suffix: matched[2], } } @@ -115,7 +114,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { error: '更新失败', checking: '检查更新中', updateAva: '发现新版本', - updateNotAva: '当前为最新版本,无需更新' + updateNotAva: '当前为最新版本,无需更新', } // 本地开发环境,改变app-update.yml地址 if (process.env.NODE_ENV === 'development') { @@ -141,11 +140,11 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { // 检查更新 const releasesApiUrl = 'https://api.github.com/repos/docmirror/dev-sidecar/releases' async function checkForUpdatesFromGitHub () { - request(releasesApiUrl, { headers: { 'User-Agent': 'DS/' + curVersion, 'Server-Name': 'baidu.com' } }, (error, response, body) => { + request(releasesApiUrl, { headers: { 'User-Agent': `DS/${curVersion}`, 'Server-Name': 'baidu.com' } }, (error, response, body) => { try { if (error) { log.error('检查更新失败:', error) - const errorMsg = '检查更新失败:' + error + const errorMsg = `检查更新失败:${error}` win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: errorMsg }) return } @@ -203,9 +202,9 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { value: { version, releaseNotes: versionData.body - ? (versionData.body.replace(/\r\n/g, '\n').replace(/https:\/\/github.com\/docmirror\/dev-sidecar/g, '').replace(/(?<=(^|\n))[ \t]*[ #]*#\s*/g, '') || '无') - : '无' - } + ? (versionData.body.replace(/\r\n/g, '\n').replace(/https:\/\/github.com\/docmirror\/dev-sidecar/g, '').replace(/(?<=(^|\n))[ \t]*(?:#[ #]*)?#\s*/g, '') || '无') + : '无', + }, }) } else { log.info(`检查更新:没有新版本,最近发布的版本号为 '${version}',而当前版本号为 '${curVersion}'`) @@ -229,15 +228,15 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { let message if (response) { - message = '检查更新失败: ' + (bodyObj && bodyObj.message ? bodyObj.message : response.message) + ', code: ' + response.statusCode + message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : response.message}, code: ${response.statusCode}` } else { - message = '检查更新失败: ' + (bodyObj && bodyObj.message ? bodyObj.message : body) + message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : body}` } win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: message }) } } catch (e) { log.error('检查更新失败:', e) - win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: '检查更新失败:' + e.message }) + win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: `检查更新失败:${e.message}` }) } }) } @@ -252,10 +251,10 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } catch (e) { fs.mkdirSync(fileDir) } - const filePath = path.join(fileDir, value.version + '.zip') + const filePath = path.join(fileDir, `${value.version}.zip`) downloadFile(value.partPackage, filePath, (data) => { - win.webContents.send('update', { key: 'progress', value: parseInt(data) }) + win.webContents.send('update', { key: 'progress', value: Number.parseInt(data) }) }, () => { // 文件下载完成 win.webContents.send('update', { key: 'progress', value: 100 }) @@ -263,10 +262,10 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { partPackagePath = filePath win.webContents.send('update', { key: 'downloaded', - value: value + value, }) }, (error) => { - sendUpdateMessage({ key: 'error', value: error, error: error }) + sendUpdateMessage({ key: 'error', value: error, error }) }) } @@ -294,34 +293,34 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } } - autoUpdater.on('error', function (error) { + autoUpdater.on('error', (error) => { log.warn('autoUpdater error:', error) - sendUpdateMessage({ key: 'error', value: error, error: error }) + sendUpdateMessage({ key: 'error', value: error, error }) // dialog.showErrorBox('Error: ', error == null ? 'unknown' : (error.stack || error).toString()) }) - autoUpdater.on('checking-for-update', function () { + autoUpdater.on('checking-for-update', () => { log.info('autoUpdater checking-for-update') sendUpdateMessage({ key: 'checking', value: message.checking }) }) - autoUpdater.on('update-available', function (info) { + autoUpdater.on('update-available', (info) => { log.info('autoUpdater update-available') sendUpdateMessage({ key: 'available', value: info }) }) - autoUpdater.on('update-not-available', function () { + autoUpdater.on('update-not-available', () => { log.info('autoUpdater update-not-available') sendUpdateMessage({ key: 'notAvailable', value: message.updateNotAva }) }) // 更新下载进度 - autoUpdater.on('download-progress', function (progressObj) { + autoUpdater.on('download-progress', (progressObj) => { log.info('autoUpdater download-progress') - win.webContents.send('update', { key: 'progress', value: parseInt(progressObj.percent) }) + win.webContents.send('update', { key: 'progress', value: Number.parseInt(progressObj.percent) }) }) // 更新完成,重启应用 - autoUpdater.on('update-downloaded', function (info) { + autoUpdater.on('update-downloaded', (info) => { log.info('download complete, version:', info.version) win.webContents.send('update', { key: 'downloaded', - value: info + value: info, }) }) @@ -374,9 +373,9 @@ export default { Object.defineProperty(app, 'isPackaged', { get () { return true - } + }, }) } updateHandle(app, api, win, beforeQuit, quit, log) - } + }, } diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js index 60f1370..3cfa1b8 100644 --- a/packages/gui/src/bridge/update/front.js +++ b/packages/gui/src/bridge/update/front.js @@ -22,7 +22,7 @@ function install (app, api) { }, doUpdateNow () { api.ipc.send('update', { key: 'doUpdateNow' }) - } + }, } function handleUpdateMessage (message) { @@ -80,15 +80,17 @@ function install (app, api) { cancelText: '取消', okText: '打开链接', width: 420, - content: h => { - return
-
请前往 github项目release页面 下载新版本手动安装
-
https://github.com/docmirror/dev-sidecar/releases
-
+ content: (h) => { + return ( +
+
请前往 github项目release页面 下载新版本手动安装
+
https://github.com/docmirror/dev-sidecar/releases
+
+ ) }, onOk () { openGithubUrl() - } + }, }) } @@ -141,31 +143,35 @@ function install (app, api) { } console.log(value) app.$confirm({ - title: '发现新版本:v' + value.version, + title: `发现新版本:v${value.version}`, cancelText: '暂不升级', okText: '升级', width: 700, - content: h => { + content: (h) => { if (value.releaseNotes) { const notes = [] if (typeof value.releaseNotes === 'string') { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') - return
-
发布公告:https://github.com/docmirror/dev-sidecar/releases
-
-
-                {releaseNotes}
-              
-
+ return ( +
+
发布公告:https://github.com/docmirror/dev-sidecar/releases
+
+
+                  {releaseNotes}
+                
+
+ ) } else { for (const note of value.releaseNotes) { notes.push(
  • {note}
  • ) } - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    更新内容:
    -
      {notes}
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    更新内容:
    +
      {notes}
    +
    + ) } } }, @@ -175,7 +181,7 @@ function install (app, api) { }, onCancel () { console.log('Cancel') - } + }, }) } @@ -187,37 +193,41 @@ function install (app, api) { cancelText: '暂不升级', okText: '立即升级', width: 700, - content: h => { + content: (h) => { if (value.releaseNotes) { const notes = [] if (typeof value.releaseNotes === 'string') { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    -
    -                {releaseNotes}
    -              
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    +
    +                  {releaseNotes}
    +                
    +
    + ) } else { for (const note of value.releaseNotes) { notes.push(
  • {note}
  • ) } - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    更新内容:
    -
      {notes}
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    更新内容:
    +
      {notes}
    +
    + ) } } }, onOk () { api.update.doUpdateNow() - } + }, }) } } export default { - install + install, } diff --git a/packages/gui/src/main.js b/packages/gui/src/main.js index 14e34d1..bd25d95 100644 --- a/packages/gui/src/main.js +++ b/packages/gui/src/main.js @@ -1,11 +1,11 @@ -import Vue from 'vue' -import App from './view/App.vue' import antd from 'ant-design-vue' -import 'ant-design-vue/dist/antd.css' -import view from './view' +import Vue from 'vue' import VueRouter from 'vue-router' -import routes from './view/router' +import view from './view' +import App from './view/App.vue' import DsContainer from './view/components/container' +import routes from './view/router' +import 'ant-design-vue/dist/antd.css' import './view/style/index.scss' import './view/style/theme/dark.scss' // 暗色主题 @@ -16,11 +16,11 @@ Vue.component(DsContainer) // 3. 创建 router 实例,然后传 `routes` 配置 // 你还可以传别的配置参数, 不过先这么简单着吧。 const router = new VueRouter({ - routes // (缩写) 相当于 routes: routes + routes, // (缩写) 相当于 routes: routes }) const app = new Vue({ router, - render: h => h(App) + render: h => h(App), }) view.initApi(app).then(async (api) => { // 初始化status diff --git a/packages/gui/src/utils/util.apppath.js b/packages/gui/src/utils/util.apppath.js index 10ac6b9..18878bb 100644 --- a/packages/gui/src/utils/util.apppath.js +++ b/packages/gui/src/utils/util.apppath.js @@ -1,5 +1,6 @@ -import path from 'path' import os from 'os' +import path from 'path' + function getSystemPlatform () { switch (os.platform()) { case 'darwin': @@ -22,5 +23,5 @@ export default { return path.join(exePath, '../../') } return path.join(exePath, '../') - } + }, } diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js index 533a666..a744d88 100644 --- a/packages/gui/src/utils/util.log.js +++ b/packages/gui/src/utils/util.log.js @@ -1,14 +1,17 @@ -const log4js = require('log4js') +const path = require('path') const DevSidecar = require('@docmirror/dev-sidecar') +const log4js = require('log4js') + +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' + const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath } -const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' -const path = require('path') + const filename = path.join(getDefaultConfigBasePath(), '/logs/gui.log') log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } }, - categories: { default: { appenders: ['file', 'std'], level } } + categories: { default: { appenders: ['file', 'std'], level } }, }) const logger = log4js.getLogger('gui') module.exports = logger diff --git a/packages/gui/src/view/api.js b/packages/gui/src/view/api.js index df2cc41..a4a72f6 100644 --- a/packages/gui/src/view/api.js +++ b/packages/gui/src/view/api.js @@ -1,13 +1,14 @@ -import lodash from 'lodash' import { ipcRenderer, shell } from 'electron' +import lodash from 'lodash' + let inited = false let apiObj = null export function apiInit (app) { const invoke = (api, args) => { - return ipcRenderer.invoke('apiInvoke', [api, args]).catch(e => { + return ipcRenderer.invoke('apiInvoke', [api, args]).catch((e) => { app.$notification.error({ message: 'Api invoke error', - description: e.message + description: e.message, }) }) } @@ -31,8 +32,8 @@ export function apiInit (app) { }, openPath (file) { shell.openPath(file) - } - } + }, + }, } const bindApi = (api, param1) => { @@ -42,7 +43,7 @@ export function apiInit (app) { } if (!inited) { - return invoke('getApiList').then(list => { + return invoke('getApiList').then((list) => { inited = true for (const item of list) { bindApi(item) diff --git a/packages/gui/src/view/index.js b/packages/gui/src/view/index.js index fd47518..a02074c 100644 --- a/packages/gui/src/view/index.js +++ b/packages/gui/src/view/index.js @@ -1,6 +1,7 @@ -import { apiInit, useApi } from './api' import modules from '../bridge/front' +import { apiInit, useApi } from './api' import status from './status' + export default { initApi: apiInit, async initPre (Vue, api) { @@ -8,12 +9,12 @@ export default { const setting = await api.setting.load() Vue.prototype.$global = { setting, - config: await api.config.get() + config: await api.config.get(), } await status.install(api) }, initModules (app, router) { const api = useApi() modules.install(app, api, router) - } + }, } diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js index 9ebdb01..aa94c86 100644 --- a/packages/gui/src/view/mixins/plugin.js +++ b/packages/gui/src/view/mixins/plugin.js @@ -1,9 +1,9 @@ -import DsContainer from '../components/container' import lodash from 'lodash' +import DsContainer from '../components/container' export default { components: { - DsContainer + DsContainer, }, data () { return { @@ -14,7 +14,7 @@ export default { wrapperCol: { span: 19 }, resetDefaultLoading: false, applyLoading: false, - systemPlatform: '' + systemPlatform: '', } }, created () { @@ -77,7 +77,7 @@ export default { this.resetDefaultLoading = false } }, - onCancel () {} + onCancel () {}, }) }, saveConfig () { @@ -137,6 +137,6 @@ export default { }, isLinux () { return this.systemPlatform === 'linux' - } - } + }, + }, } diff --git a/packages/gui/src/view/router/index.js b/packages/gui/src/view/router/index.js index e8c11c7..d237950 100644 --- a/packages/gui/src/view/router/index.js +++ b/packages/gui/src/view/router/index.js @@ -1,10 +1,10 @@ import Index from '../pages/index' -import Server from '../pages/server' -import Proxy from '../pages/proxy' -import Node from '../pages/plugin/node' import Git from '../pages/plugin/git' -import Pip from '../pages/plugin/pip' +import Node from '../pages/plugin/node' import Overwall from '../pages/plugin/overwall' +import Pip from '../pages/plugin/pip' +import Proxy from '../pages/proxy' +import Server from '../pages/server' import Setting from '../pages/setting' const routes = [ @@ -12,12 +12,11 @@ const routes = [ { path: '/index', component: Index }, { path: '/server', component: Server }, { path: '/proxy', component: Proxy }, + { path: '/setting', component: Setting }, { path: '/plugin/node', component: Node }, { path: '/plugin/git', component: Git }, { path: '/plugin/pip', component: Pip }, { path: '/plugin/overwall', component: Overwall }, - { path: '/setting', component: Setting } - ] export default routes diff --git a/packages/gui/src/view/router/menu.js b/packages/gui/src/view/router/menu.js index 5655bd5..f03e97c 100644 --- a/packages/gui/src/view/router/menu.js +++ b/packages/gui/src/view/router/menu.js @@ -2,7 +2,7 @@ export default function createMenus (app) { const plugins = [ { title: 'NPM加速', path: '/plugin/node', icon: 'like' }, { title: 'Git.exe代理', path: '/plugin/git', icon: 'github' }, - { title: 'pip加速', path: '/plugin/pip', icon: 'bulb' } + { title: 'pip加速', path: '/plugin/pip', icon: 'bulb' }, ] const menus = [ { title: '首页', path: '/index', icon: 'home' }, @@ -13,8 +13,8 @@ export default function createMenus (app) { title: '应用', path: '/plugin', icon: 'api', - children: plugins - } + children: plugins, + }, ] if (app.$global && app.$global.setting && app.$global.setting.overwall) { plugins.push({ title: '功能增强', path: '/plugin/overwall', icon: 'global' }) diff --git a/packages/gui/src/view/status.js b/packages/gui/src/view/status.js index 47942f6..a8db1d7 100644 --- a/packages/gui/src/view/status.js +++ b/packages/gui/src/view/status.js @@ -1,15 +1,16 @@ import lodash from 'lodash' import Vue from 'vue' + const status = { server: { - enabled: false + enabled: false, }, proxy: { - enabled: false + enabled: false, }, plugin: { - node: {} - } + node: {}, + }, } async function install (api) { api.ipc.on('status', (event, message) => { @@ -25,5 +26,5 @@ async function install (api) { } export default { install, - status + status, } diff --git a/packages/gui/vue.config.js b/packages/gui/vue.config.js index c20ffc3..14b35db 100644 --- a/packages/gui/vue.config.js +++ b/packages/gui/vue.config.js @@ -1,19 +1,24 @@ const path = require('path') const webpack = require('webpack') + const publishUrl = process.env.VUE_APP_PUBLISH_URL const publishProvider = process.env.VUE_APP_PUBLISH_PROVIDER console.log('Publish url:', publishUrl) + +/** + * @type {import('@vue/cli-service').ProjectOptions} + */ module.exports = { pages: { index: { entry: 'src/main.js', - title: 'DevSidecar-给开发者的边车辅助工具' - } + title: 'DevSidecar-给开发者的边车辅助工具', + }, }, configureWebpack: (config) => { - const configNew = { + return { plugins: [ - new webpack.DefinePlugin({ 'global.GENTLY': true }) + new webpack.DefinePlugin({ 'global.GENTLY': true }), ], module: { rules: [ @@ -21,14 +26,13 @@ module.exports = { test: /\.json5$/i, loader: 'json5-loader', options: { - esModule: false + esModule: false, }, - type: 'javascript/auto' - } - ] - } + type: 'javascript/auto', + }, + ], + }, } - return configNew }, pluginOptions: { electronBuilder: { @@ -51,7 +55,7 @@ module.exports = { '@natmri/platform-napi-linux-arm64-musl', '@natmri/platform-napi-linux-arm-gnueabihf', '@natmri/platform-napi-darwin-x64', - '@natmri/platform-napi-darwin-arm64' + '@natmri/platform-napi-darwin-arm64', ], nodeIntegration: true, // Provide an array of files that, when changed, will recompile the main process and restart Electron @@ -67,8 +71,8 @@ module.exports = { extraResources: [ { from: 'extra', - to: 'extra' - } + to: 'extra', + }, ], appId: 'dev-sidecar', productName: 'dev-sidecar', @@ -80,35 +84,35 @@ module.exports = { perMachine: true, allowElevation: true, allowToChangeInstallationDirectory: true, - include: './build/installer.nsh' + include: './build/installer.nsh', }, mac: { icon: './build/mac/icon.icns', target: { arch: 'universal', - target: 'dmg' - } + target: 'dmg', + }, }, win: { - icon: 'build/icons/' + icon: 'build/icons/', // requestedExecutionLevel: 'highestAvailable' // 加了这个无法开机自启 }, linux: { icon: 'build/mac/', target: [ 'deb', - 'AppImage' - ] + 'AppImage', + ], }, publish: { provider: publishProvider, - url: publishUrl + url: publishUrl, // url: 'http://dev-sidecar.docmirror.cn/update/preview/' - } + }, }, chainWebpackMainProcess (config) { config.entry('mitmproxy').add(path.join(__dirname, 'src/bridge/mitmproxy.js')) - } - } - } + }, + }, + }, }