Browse Source

perf: 关闭策略

pull/192/head
xiaojunnuo 3 years ago
parent
commit
ca863da878
  1. 3
      packages/core/src/config/index.js
  2. 24
      packages/gui/src/background.js
  3. 5
      packages/gui/src/bridge/front.js
  4. 49
      packages/gui/src/bridge/on-close/front.js
  5. 1
      packages/gui/src/view/pages/index.vue
  6. 17
      packages/gui/src/view/pages/setting.vue

3
packages/core/src/config/index.js

@ -21,7 +21,8 @@ module.exports = {
},
dock: {
hideWhenWinClose: false
}
},
closeStrategy: 0
},
server: {
enabled: true,

24
packages/gui/src/background.js

@ -173,9 +173,29 @@ function createWindow (startHideWindow) {
tray = null
})
ipcMain.on('close', async (event, message) => {
if (message.value === 1) {
quit()
} else {
hideWin()
}
})
win.on('close', (e) => {
if (!forceClose) {
e.preventDefault()
if (forceClose) {
return
}
e.preventDefault()
const config = DevSidecar.api.config.get()
const closeStrategy = config.app.closeStrategy
if (closeStrategy === 0) {
// 提醒
win.webContents.send('close.showTip')
} else if (closeStrategy === 1) {
// 直接退出
quit()
} else if (closeStrategy === 2) {
// 隐藏窗口
hideWin()
}
})

5
packages/gui/src/bridge/front.js

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

49
packages/gui/src/bridge/on-close/front.js

@ -0,0 +1,49 @@
function install (app, api) {
api.ipc.on('close.showTip', (event, message) => {
console.error('error', event, message)
const result = {
closeType: 1,
save: false
}
function onRadioChange (event) {
result.closeType = event.target.value
}
function onCheckChange (event) {
result.save = event.target.checked
}
app.$confirm({
title: '关闭策略',
content: h => <div>
<div>
<a-radio-group vOn:change={onRadioChange}>
<a-radio value={1}>
直接关闭
</a-radio>
<a-radio value={2}>
最小化到系统托盘
</a-radio>
</a-radio-group>
</div>
<div>
<a-checkbox vOn:change={onCheckChange} >
记住本次选择不再提示
< /a-checkbox>
</div>
</div>,
async onOk () {
console.log('OK')
if (result.save) {
await api.config.save({ app: { closeStrategy: result.closeType } })
}
api.ipc.send('close', { key: 'selected', value: result.closeType })
},
onCancel () {
console.log('Cancel')
}
})
})
}
export default {
install
}

1
packages/gui/src/view/pages/index.vue

@ -19,6 +19,7 @@
</template>
<div class="box">
<a-alert message="本应用开启后会修改系统代理,直接重启电脑可能会无法上网,您可以再次启动本应用即可恢复。如您需要卸载,在卸载前请务必右键右下角小图标退出本应用再进行卸载" banner />
<div class="mode-bar" style="margin:20px;" v-if="config && config.app">
<a-radio-group v-model="config.app.mode" button-style="solid" @change="modeChange">
<a-tooltip placement="topLeft" title="启用测速,关闭拦截,关闭增强(功能最弱,不稳定,不需要安装证书,最安全)">

17
packages/gui/src/view/pages/setting.vue

@ -35,6 +35,23 @@
<a-form-item label="远程配置地址" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-input v-model="config.app.remoteConfig.url"></a-input>
</a-form-item>
<a-form-item label="关闭策略" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-radio-group v-model="config.app.closeStrategy"
default-value="0" button-style="solid">
<a-radio-button :value="0">
弹出提示
</a-radio-button>
<a-radio-button :value="1">
直接退出
</a-radio-button>
<a-radio-button :value="2">
最小化到系统托盘
</a-radio-button>
</a-radio-group>
<div class="form-help">
点击窗口右上角关闭按钮的效果
</div>
</a-form-item>
</div>
<template slot="footer">
<div class="footer-bar">

Loading…
Cancel
Save