From 2cabe6e58e570e356dce6afa1749e7f48ad33965 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 2 May 2020 18:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E9=80=89=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 2 +- src/main/rendererEvents/winEvent.js | 3 ++ src/renderer/config/bindkey.js | 58 ++++++++++++++--------------- src/renderer/config/event.js | 11 ++++++ src/renderer/main.js | 8 +--- 5 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 src/renderer/config/event.js diff --git a/publish/changeLog.md b/publish/changeLog.md index 105616e8..90a434e3 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,3 @@ ### 修复 -- 修复开启托盘时,可能导致无法自动更新的问题 +- 修复按住`Ctrl`等键触发多选机制时不松开按键的情况下切换到其他窗口后再松开按键,这时切回软件不按按键都处在多选模式的问题 diff --git a/src/main/rendererEvents/winEvent.js b/src/main/rendererEvents/winEvent.js index 5bbd0139..35d0df1f 100644 --- a/src/main/rendererEvents/winEvent.js +++ b/src/main/rendererEvents/winEvent.js @@ -21,6 +21,9 @@ module.exports = mainWindow => { // mainWindow.on('restore', () => { // mainWindow.webContents.send('restore') // }) + mainWindow.on('focus', () => { + mainWindow.webContents.send('focus') + }) mainWindow.once('ready-to-show', () => { mainWindow.show() diff --git a/src/renderer/config/bindkey.js b/src/renderer/config/bindkey.js index 9eb16f47..eaddc52d 100644 --- a/src/renderer/config/bindkey.js +++ b/src/renderer/config/bindkey.js @@ -1,41 +1,38 @@ import mousetrap from 'mousetrap' + let eventHub +const bindKeys = [ + 'shift', + 'mod', + 'mod+a', +] + const bindKey = () => { mousetrap.reset() - mousetrap.bind('shift', (event, combo) => { - eventHub.$emit('key_shift_down', { event, combo }) - return false - }, 'keydown') - mousetrap.bind('shift', (event, combo) => { - eventHub.$emit('key_shift_up', { event, combo }) - return false - }, 'keyup') - mousetrap.bind('mod', (event, combo) => { - eventHub.$emit('key_mod_down', { event, combo }) - return false - }, 'keydown') - mousetrap.bind('mod', (event, combo) => { - eventHub.$emit('key_mod_up', { event, combo }) - return false - }, 'keyup') - mousetrap.bind('mod+a', (event, combo) => { - eventHub.$emit('key_mod+a_down', { event, combo }) - return false - }, 'keydown') - mousetrap.bind('mod+a', (event, combo) => { - eventHub.$emit('key_mod+a_up', { event, combo }) - return false - }, 'keyup') + for (const key of bindKeys) { + mousetrap.bind(key, (event, combo) => { + eventHub.$emit(`key_${key}_down`, { event, combo }) + return false + }, 'keydown') + mousetrap.bind(key, (event, combo) => { + eventHub.$emit(`key_${key}_up`, { event, combo }) + return false + }, 'keyup') + } } const unbindKey = () => { - mousetrap.unbind('shift', 'keydown') - mousetrap.unbind('shift', 'keyup') - mousetrap.unbind('mod', 'keydown') - mousetrap.unbind('mod', 'keyup') - mousetrap.unbind('mod+a', 'keydown') - mousetrap.unbind('mod+a', 'keyup') + for (const key of bindKeys) { + mousetrap.unbind(key, 'keydown') + mousetrap.unbind(key, 'keyup') + } +} + +const handleFocus = () => { + for (const key of bindKeys) { + eventHub.$emit(`key_${key}_up`, { combo: key }) + } } export default () => { @@ -43,4 +40,5 @@ export default () => { eventHub.$on('bindKey', bindKey) eventHub.$on('unbindKey', unbindKey) + eventHub.$on('focus', handleFocus) } diff --git a/src/renderer/config/event.js b/src/renderer/config/event.js new file mode 100644 index 00000000..e4e0cb6d --- /dev/null +++ b/src/renderer/config/event.js @@ -0,0 +1,11 @@ +import Vue from 'vue' +import bindkey from './bindkey' +import { rendererOn } from '../../common/ipc' + +window.eventHub = new Vue() + +bindkey() + +rendererOn('focus', () => { + window.eventHub.$emit('focus') +}) diff --git a/src/renderer/main.js b/src/renderer/main.js index bfc2085f..d2791bc8 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -1,6 +1,8 @@ import Vue from 'vue' import { sync } from 'vuex-router-sync' +import './config/event' + // Components import './components' @@ -14,14 +16,8 @@ import store from './store' import '../common/error' -import bindkey from './config/bindkey' - sync(store, router) -window.eventHub = new Vue() - -bindkey() - Vue.config.productionTip = false new Vue({