refactor: autostart

pull/67/head
xiaojunnuo 2021-03-27 17:06:49 +08:00
parent c93ac9be99
commit a3c4b2a206
11 changed files with 119 additions and 19 deletions

View File

@ -11,7 +11,10 @@ function getRootCaKeyPath () {
}
module.exports = {
app: {
mode: 'default'
mode: 'default',
autoStart: {
enabled: false
}
},
server: {
enabled: true,

View File

@ -0,0 +1,29 @@
export default {
install (context) {
const { ipcMain, dialog, log, app } = context
const ex = process.execPath
// 定义事件,渲染进程中直接使用
// 开启 开机自启动
ipcMain.on('auto-start', (event, message) => {
console.log('updateExe', ex)
if (message.value) {
app.setLoginItemSettings({
openAtLogin: true,
path: ex,
args: []
})
event.sender.send('auto-start', { key: 'enabled', value: true })
} else {
app.setLoginItemSettings({
openAtLogin: false,
path: ex,
args: []
})
event.sender.send('auto-start', { key: 'enabled', value: false })
}
})
}
}

View File

@ -0,0 +1,19 @@
function install (app, api) {
api.ipc.on('auto-start', (event, message) => {
if (message.value === true) {
app.$message.info('已添加开机自启')
} else {
app.$message.info('已取消开机自启')
}
})
api.autoStart = {
async enabled (value) {
api.ipc.send('auto-start', { key: 'enabled', value })
}
}
}
export default {
install
}

View File

@ -2,12 +2,14 @@ import api from './api/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 // 自动更新
update, // 自动更新
autoStart
}
export default {
install (context) {

View File

@ -3,13 +3,15 @@ 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'
const modules = {
// api, // 核心接口模块
error,
fileSelector, // 文件选择模块
tongji, // 统计模块
update // 自动更新
update, // 自动更新
autoStart
}
export default {
install (app, api, router) {

View File

@ -0,0 +1,50 @@
<template>
<ds-container>
<template slot="header">
设置
<span>
</span>
</template>
<div v-if="config">
<a-form-item label="开机自启" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.app.autoStart.enabled" @change="onAutoStartChange">
开机自启
</a-checkbox>
</a-form-item>
</div>
<template slot="footer">
<div class="footer-bar">
<a-button class="md-mr-10" icon="sync" @click="resetDefault()"></a-button>
<a-button :loading="applyLoading" icon="check" type="primary" @click="apply()"></a-button>
</div>
</template>
</ds-container>
</template>
<script>
import Plugin from '../mixins/plugin'
export default {
name: 'Setting',
mixins: [Plugin],
data () {
return {
key: 'app'
}
},
created () {
},
mounted () {
},
methods: {
onAutoStartChange () {
this.$api.autoStart.enabled(this.config.app.autoStart.enabled)
this.saveConfig()
}
}
}
</script>
<style lang="sass">
</style>

View File

@ -4,6 +4,7 @@ import Proxy from '../pages/proxy'
import Node from '../pages/plugin/node'
import Git from '../pages/plugin/git'
import Overwall from '../pages/plugin/overwall'
import Setting from '../pages/setting'
const routes = [
{ path: '/', redirect: '/index' },
@ -12,7 +13,8 @@ const routes = [
{ path: '/proxy', component: Proxy },
{ path: '/plugin/node', component: Node },
{ path: '/plugin/git', component: Git },
{ path: '/plugin/overwall', component: Overwall }
{ path: '/plugin/overwall', component: Overwall },
{ path: '/setting', component: Setting }
]

View File

@ -7,6 +7,7 @@ export default function createMenus (app) {
{ title: '首页', path: '/index', icon: 'home' },
{ title: '加速服务', path: '/server', icon: 'thunderbolt' },
{ title: '系统代理', path: '/proxy', icon: 'deployment-unit' },
{ title: '设置', path: '/setting', icon: 'setting' },
{
title: '应用',
path: '/plugin',

View File

@ -3514,7 +3514,7 @@ commander@2.17.x:
resolved "https://registry.npm.taobao.org/commander/download/commander-2.17.1.tgz?cache=0&sync_timestamp=1598576116597&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.17.1.tgz"
integrity sha1-vXerfebelCBc6sxy8XFtKfIKd78=
commander@^2.18.0, commander@^2.2.0, commander@^2.20.0, commander@^2.9.0:
commander@^2.18.0, commander@^2.20.0, commander@^2.9.0:
version "2.20.3"
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@ -7082,11 +7082,6 @@ lie@~3.3.0:
dependencies:
immediate "~3.0.5"
limiter@^1.0.5:
version "1.1.5"
resolved "https://registry.npm.taobao.org/limiter/download/limiter-1.1.5.tgz#8f92a25b3b16c6131293a0cc834b4a838a2aa7c2"
integrity sha1-j5KiWzsWxhMSk6DMg0tKg4oqp8I=
lines-and-columns@^1.1.6:
version "1.1.6"
resolved "https://registry.npm.taobao.org/lines-and-columns/download/lines-and-columns-1.1.6.tgz"
@ -10132,14 +10127,6 @@ stream-shift@^1.0.0:
resolved "https://registry.npm.taobao.org/stream-shift/download/stream-shift-1.0.1.tgz"
integrity sha1-1wiCgVWasneEJCebCHfaPDktWj0=
stream-throttle@^0.1.3:
version "0.1.3"
resolved "https://registry.npm.taobao.org/stream-throttle/download/stream-throttle-0.1.3.tgz#add57c8d7cc73a81630d31cd55d3961cfafba9c3"
integrity sha1-rdV8jXzHOoFjDTHNVdOWHPr7qcM=
dependencies:
commander "^2.2.0"
limiter "^1.0.5"
streamroller@^2.2.4:
version "2.2.4"
resolved "https://registry.npmjs.org/streamroller/-/streamroller-2.2.4.tgz"

View File

@ -0,0 +1,5 @@
module.exports = {
lookup () {
}
}

View File

@ -276,7 +276,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (!res.writableEnded) {
const status = e.status || 500
res.writeHead(status, { 'Content-Type': 'text/html;charset=UTF8' })
res.write(`DevSidecar Warning:\n\n ${e.toString()}`)
res.write(`DevSidecar Warning:<br/> ${e.toString()}`)
res.end()
log.error('request error', e.message)
}