optimize: 快捷键设置保存后立即生效;关闭策略提示窗优化。
parent
f32cabd40f
commit
4179fb111c
|
@ -228,8 +228,8 @@ function createWindow (startHideWindow) {
|
|||
const config = DevSidecar.api.config.get()
|
||||
const closeStrategy = config.app.closeStrategy
|
||||
if (closeStrategy === 0) {
|
||||
// 提醒
|
||||
win.webContents.send('close.showTip')
|
||||
// 弹窗提示,选择关闭策略
|
||||
win.webContents.send('close.showTip', closeStrategy)
|
||||
} else if (closeStrategy === 1) {
|
||||
// 直接退出
|
||||
quit()
|
||||
|
@ -269,7 +269,7 @@ function createWindow (startHideWindow) {
|
|||
}
|
||||
win.webContents.executeJavaScript('config')
|
||||
.then((value) => {
|
||||
console.info('window.config:', value)
|
||||
console.info('window.config:', value, ', key:', input.key)
|
||||
if (!value || (value.disableBeforeInputEvent !== true && value.disableBeforeInputEvent !== 'true')) {
|
||||
shortcut(event, input)
|
||||
}
|
||||
|
@ -278,6 +278,14 @@ function createWindow (startHideWindow) {
|
|||
shortcut(event, input)
|
||||
})
|
||||
})
|
||||
|
||||
// 监听渲染进程发送过来的消息
|
||||
win.webContents.on('ipc-message', (event, channel, message) => {
|
||||
console.info(arguments)
|
||||
if (channel === 'change-showHideShortcut') {
|
||||
registerShowHideShortcut(message)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function beforeQuit () {
|
||||
|
@ -292,6 +300,37 @@ async function quit () {
|
|||
app.quit()
|
||||
}
|
||||
|
||||
function registerShowHideShortcut (showHideShortcut) {
|
||||
globalShortcut.unregisterAll()
|
||||
if (showHideShortcut && showHideShortcut !== '无' && showHideShortcut.length > 1) {
|
||||
try {
|
||||
const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
|
||||
if (winIsHidden || !win.isFocused()) {
|
||||
if (!win.isFocused()) {
|
||||
win.focus()
|
||||
}
|
||||
if (winIsHidden) {
|
||||
showWin()
|
||||
}
|
||||
} else {
|
||||
// linux,快捷键不关闭窗口
|
||||
if (!isLinux()) {
|
||||
hideWin()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (registerSuccess) {
|
||||
log.info('注册快捷键成功:', DevSidecar.api.config.get().app.showHideShortcut)
|
||||
} else {
|
||||
log.error('注册快捷键失败:', DevSidecar.api.config.get().app.showHideShortcut)
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('注册快捷键异常:', DevSidecar.api.config.get().app.showHideShortcut, ', error:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initApp () {
|
||||
if (isMac) {
|
||||
app.whenReady().then(() => {
|
||||
|
@ -301,36 +340,10 @@ function initApp () {
|
|||
|
||||
// 全局监听快捷键,用于 显示/隐藏 窗口
|
||||
app.whenReady().then(async () => {
|
||||
const showHideShortcut = DevSidecar.api.config.get().app.showHideShortcut
|
||||
if (showHideShortcut && showHideShortcut !== '无' && showHideShortcut.length > 1) {
|
||||
try {
|
||||
const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
|
||||
if (winIsHidden || !win.isFocused()) {
|
||||
if (!win.isFocused()) {
|
||||
win.focus()
|
||||
}
|
||||
if (winIsHidden) {
|
||||
showWin()
|
||||
}
|
||||
} else {
|
||||
// linux,快捷键不关闭窗口
|
||||
if (!isLinux()) {
|
||||
hideWin()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (registerSuccess) {
|
||||
log.info('注册快捷键成功:', DevSidecar.api.config.get().app.showHideShortcut)
|
||||
} else {
|
||||
log.error('注册快捷键失败:', DevSidecar.api.config.get().app.showHideShortcut)
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('注册快捷键异常:', DevSidecar.api.config.get().app.showHideShortcut, ', error:', e)
|
||||
}
|
||||
}
|
||||
registerShowHideShortcut(DevSidecar.api.config.get().app.showHideShortcut)
|
||||
})
|
||||
}
|
||||
|
||||
// -------------执行开始---------------
|
||||
app.disableHardwareAcceleration() // 禁用gpu
|
||||
|
||||
|
|
|
@ -1,44 +1,39 @@
|
|||
let closeType = 1
|
||||
let doSave = false
|
||||
|
||||
function install (app, api) {
|
||||
api.ipc.on('close.showTip', (event, message) => {
|
||||
console.error('error', event, message)
|
||||
const result = {
|
||||
closeType: 1,
|
||||
save: false
|
||||
}
|
||||
console.info('ipc channel: "close.showTip", event:', event, ', message:', message)
|
||||
function onRadioChange (event) {
|
||||
result.closeType = event.target.value
|
||||
closeType = event.target.value
|
||||
}
|
||||
function onCheckChange (event) {
|
||||
result.save = event.target.checked
|
||||
doSave = event.target.checked
|
||||
}
|
||||
app.$confirm({
|
||||
title: '关闭策略',
|
||||
content: h => <div>
|
||||
<div style={'margin-top:10px'}>
|
||||
<a-radio-group vOn:change={onRadioChange}>
|
||||
<a-radio value={1}>
|
||||
直接关闭
|
||||
</a-radio>
|
||||
<a-radio value={2}>
|
||||
最小化到系统托盘
|
||||
</a-radio>
|
||||
<a-radio-group vOn:change={onRadioChange} defaultValue={closeType}>
|
||||
<a-radio value={1}>直接关闭</a-radio>
|
||||
<a-radio value={2}>最小化到系统托盘</a-radio>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
<div style={'margin-top:10px'}>
|
||||
<a-checkbox vOn:change={onCheckChange} >
|
||||
<a-checkbox vOn:change={onCheckChange} defaultChecked={doSave}>
|
||||
记住本次选择,不再提示
|
||||
< /a-checkbox>
|
||||
</div>
|
||||
</div>,
|
||||
async onOk () {
|
||||
console.log('OK')
|
||||
if (result.save) {
|
||||
await api.config.update({ app: { closeStrategy: result.closeType } })
|
||||
console.log('OK. closeType=', closeType)
|
||||
if (doSave) {
|
||||
await api.config.update({ app: { closeStrategy: closeType } })
|
||||
}
|
||||
api.ipc.send('close', { key: 'selected', value: result.closeType })
|
||||
api.ipc.send('close', { key: 'selected', value: closeType })
|
||||
},
|
||||
onCancel () {
|
||||
console.log('Cancel')
|
||||
console.log('Cancel. closeType=', closeType)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -92,8 +92,7 @@
|
|||
<a-form-item label="打开窗口快捷键" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-input v-model="config.app.showHideShortcut" @change="shortcutChange" @keydown="shortcutKeyDown" @keyup="shortcutKeyUp"></a-input>
|
||||
<div class="form-help">
|
||||
部分快捷键已被占用:F5=刷新页面,F12=开发者工具(DevTools)<br/>
|
||||
当前版本,修改快捷键后,需重启 ds 才会生效
|
||||
部分快捷键已被占用:F5=刷新页面,F12=开发者工具(DevTools)
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="启动时打开窗口" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
|
@ -154,6 +153,8 @@
|
|||
|
||||
<script>
|
||||
import Plugin from '../mixins/plugin'
|
||||
import { ipcRenderer } from 'electron'
|
||||
|
||||
export default {
|
||||
name: 'Setting',
|
||||
mixins: [Plugin],
|
||||
|
@ -325,6 +326,11 @@ export default {
|
|||
|
||||
this.config.app.showHideShortcut = shortcut
|
||||
},
|
||||
async applyBefore () {
|
||||
if (!this.config.app.showHideShortcut) {
|
||||
this.config.app.showHideShortcut = '无'
|
||||
}
|
||||
},
|
||||
async applyAfter () {
|
||||
let reloadLazy = 10
|
||||
|
||||
|
@ -339,6 +345,9 @@ export default {
|
|||
if (this.config.app.theme !== this.themeBackup) {
|
||||
setTimeout(() => window.location.reload(), reloadLazy)
|
||||
}
|
||||
|
||||
// 变更 “打开窗口快捷键”
|
||||
ipcRenderer.send('change-showHideShortcut', this.config.app.showHideShortcut)
|
||||
},
|
||||
async openExternal (url) {
|
||||
await this.$api.ipc.openExternal(url)
|
||||
|
|
Loading…
Reference in New Issue