From 1fce38ae435d4da2b3dce17f873fde9cef622143 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com>
Date: Wed, 25 Sep 2024 15:27:57 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BF=AB=E6=8D=B7=E9=94=AE?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/gui/public/index.html | 1 +
packages/gui/src/background.js | 45 ++++++++++++++++++++-----
packages/gui/src/view/pages/server.vue | 2 +-
packages/gui/src/view/pages/setting.vue | 21 ++++++++++--
4 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/packages/gui/public/index.html b/packages/gui/public/index.html
index 41cb07a..6dc2183 100644
--- a/packages/gui/public/index.html
+++ b/packages/gui/public/index.html
@@ -6,6 +6,7 @@
diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js
index 69c5675..9cf7601 100644
--- a/packages/gui/src/background.js
+++ b/packages/gui/src/background.js
@@ -118,7 +118,7 @@ function setTray () {
showWin()
})
- appTray.on('right-click', function (event, bounds) {
+ appTray.on('right-click', function () {
setTimeout(function () {
appTray.popUpContextMenu(contextMenu)
}, 200)
@@ -203,7 +203,7 @@ function createWindow (startHideWindow) {
hideWin()
}
- win.on('closed', async (e) => {
+ win.on('closed', async () => {
win = null
tray = null
})
@@ -244,12 +244,39 @@ function createWindow (startHideWindow) {
await quit()
})
- // 监听键盘事件
- win.webContents.on('before-input-event', (event, input) => {
+ const shortcut = (event, input) => {
// 按 F12,打开/关闭 开发者工具
- if (input.key === 'F12' && input.type === 'keyUp' && !input.control && !input.alt && !input.shift && !input.meta) {
+ if (input.key === 'F12') {
+ // 阻止默认的按键事件行为
+ event.preventDefault()
+ // 切换开发者工具显示状态
switchDevTools()
+ // eslint-disable-next-line brace-style
+ }
+ // 按 F5,刷新页面
+ else if (input.key === 'F5') {
+ // 阻止默认的按键事件行为
+ event.preventDefault()
+ // 刷新页面
+ win.webContents.reload()
}
+ }
+
+ // 监听键盘事件
+ win.webContents.on('before-input-event', (event, input) => {
+ if (input.type !== 'keyUp' || input.control || input.alt || input.shift || input.meta) {
+ return
+ }
+ win.webContents.executeJavaScript('config')
+ .then((value) => {
+ console.info('window.config:', value)
+ if (!value || (value.disableBeforeInputEvent !== true && value.disableBeforeInputEvent !== 'true')) {
+ shortcut(event, input)
+ }
+ })
+ .catch(() => {
+ shortcut(event, input)
+ })
})
}
@@ -333,17 +360,17 @@ if (!isFirstInstance) {
app.quit()
}, 1000)
} else {
- app.on('before-quit', async (event) => {
+ app.on('before-quit', async () => {
log.info('before-quit')
if (process.platform === 'darwin') {
quit()
}
})
app.on('will-quit', () => {
- globalShortcut.unregisterAll();
+ globalShortcut.unregisterAll()
log.info('应用关闭,注销所有快捷键')
- });
- app.on('second-instance', (event, commandLine, workingDirectory) => {
+ })
+ app.on('second-instance', (event, commandLine) => {
log.info('new app started, command:', commandLine)
if (win) {
showWin()
diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue
index 04f78d1..a9eea4a 100644
--- a/packages/gui/src/view/pages/server.vue
+++ b/packages/gui/src/view/pages/server.vue
@@ -91,7 +91,7 @@
- 这里配置哪些域名不需要通过代理
+ 这里配置的域名不会通过代理
diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue
index 9beb507..dbaa1f7 100644
--- a/packages/gui/src/view/pages/setting.vue
+++ b/packages/gui/src/view/pages/setting.vue
@@ -90,8 +90,9 @@
-
+
+ 部分快捷键已被占用:F5=刷新页面,F12=开发者工具(DevTools)
当前版本,修改快捷键后,需重启 ds 才会生效
@@ -278,10 +279,24 @@ export default {
console.error(`未能识别的按键:key=${event.key}, code=${event.code}, keyCode=${event.keyCode}`)
return ''
},
+ async disableBeforeInputEvent () {
+ clearTimeout(window.enableBeforeInputEventTimeout)
+ window.config.disableBeforeInputEvent = true
+ window.enableBeforeInputEventTimeout = setTimeout(function () {
+ window.config.disableBeforeInputEvent = false
+ }, 2000)
+ },
shortcutChange () {
this.config.app.showHideShortcut = '无'
},
+ shortcutKeyUp (event) {
+ event.preventDefault()
+ this.disableBeforeInputEvent()
+ },
shortcutKeyDown (event) {
+ event.preventDefault()
+ this.disableBeforeInputEvent()
+
// console.info(`code=${event.code}, key=${event.key}, keyCode=${event.keyCode}`)
if (event.type !== 'keydown') {
return
@@ -299,8 +314,8 @@ export default {
if (event.shiftKey) shortcut += 'Shift + '
if (event.metaKey) shortcut += 'Meta + '
- // 如果以上按钮都没有按下,并且当前键不是F1~F11,则直接返回(注:F12已经是打开DevTools的快捷键了)
- if (shortcut === '' && !key.match(/^F([1-9]|1[01])$/g)) {
+ // 如果以上按钮都没有按下,并且当前键不是F1~F4、F6~F11时,则直接返回(注:F5已经是刷新页面快捷键、F12已经是打开DevTools的快捷键了)
+ if (shortcut === '' && !key.match(/^F([12346789]|1[01])$/g)) {
this.config.app.showHideShortcut = '无'
return
}