From 3be3b0ca36b7f5e69ee5fcaa7c3da51f8fa6ea10 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 1 May 2020 20:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmac=E4=B8=8B=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=85=A8=E9=80=89=E4=B8=80=E6=AC=A1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/components/material/SongList.vue | 51 ++++++++++++------- src/renderer/config/bindkey.js | 12 ++--- src/renderer/views/Download.vue | 51 ++++++++++++------- src/renderer/views/List.vue | 51 ++++++++++++------- src/renderer/views/Search.vue | 51 ++++++++++++------- 5 files changed, 134 insertions(+), 82 deletions(-) diff --git a/src/renderer/components/material/SongList.vue b/src/renderer/components/material/SongList.vue index 4e13f6da..6dc80061 100644 --- a/src/renderer/components/material/SongList.vue +++ b/src/renderer/components/material/SongList.vue @@ -122,6 +122,7 @@ export default { isShiftDown: false, isModDown: false, isADown: false, + aDownTimeout: null, }, } }, @@ -133,41 +134,53 @@ export default { }, methods: { listenEvent() { - window.eventHub.$on('shift_down', this.handle_shift_down) - window.eventHub.$on('shift_up', this.handle_shift_up) - window.eventHub.$on('mod_down', this.handle_mod_down) - window.eventHub.$on('mod_up', this.handle_mod_up) - window.eventHub.$on('mod+a_down', this.handle_mod_a_down) - window.eventHub.$on('mod+a_up', this.handle_mod_a_up) + window.eventHub.$on('key_shift_down', this.handle_key_shift_down) + window.eventHub.$on('key_shift_up', this.handle_key_shift_up) + window.eventHub.$on('key_mod_down', this.handle_key_mod_down) + window.eventHub.$on('key_mod_up', this.handle_key_mod_up) + window.eventHub.$on('key_mod+a_down', this.handle_key_mod_a_down) + window.eventHub.$on('key_mod+a_up', this.handle_key_mod_a_up) }, unlistenEvent() { - window.eventHub.$off('shift_down', this.handle_shift_down) - window.eventHub.$off('shift_up', this.handle_shift_up) - window.eventHub.$off('mod_down', this.handle_mod_down) - window.eventHub.$off('mod_up', this.handle_mod_up) - window.eventHub.$off('mod+a_down', this.handle_mod_a_down) - window.eventHub.$off('mod+a_up', this.handle_mod_a_up) + window.eventHub.$off('key_shift_down', this.handle_key_shift_down) + window.eventHub.$off('key_shift_up', this.handle_key_shift_up) + window.eventHub.$off('key_mod_down', this.handle_key_mod_down) + window.eventHub.$off('key_mod_up', this.handle_key_mod_up) + window.eventHub.$off('key_mod+a_down', this.handle_key_mod_a_down) + window.eventHub.$off('key_mod+a_up', this.handle_key_mod_a_up) }, - handle_shift_down() { + handle_key_shift_down() { if (!this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = true }, - handle_shift_up() { + handle_key_shift_up() { if (this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = false }, - handle_mod_down() { + handle_key_mod_down() { if (!this.keyEvent.isModDown) this.keyEvent.isModDown = true }, - handle_mod_up() { + handle_key_mod_up() { if (this.keyEvent.isModDown) this.keyEvent.isModDown = false }, - handle_mod_a_down() { + handle_key_mod_a_down() { if (!this.keyEvent.isADown) { + this.keyEvent.isModDown = false this.keyEvent.isADown = true this.handleSelectAllData() + if (this.keyEvent.aDownTimeout) clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = setTimeout(() => { + this.keyEvent.aDownTimeout = null + this.keyEvent.isADown = false + }, 500) } }, - handle_mod_a_up() { - if (this.keyEvent.isADown) this.keyEvent.isADown = false + handle_key_mod_a_up() { + if (this.keyEvent.isADown) { + if (this.keyEvent.aDownTimeout) { + clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = null + } + this.keyEvent.isADown = false + } }, handleDoubleClick(event, index) { if (event.target.classList.contains('select')) return diff --git a/src/renderer/config/bindkey.js b/src/renderer/config/bindkey.js index 3991a0ae..9eb16f47 100644 --- a/src/renderer/config/bindkey.js +++ b/src/renderer/config/bindkey.js @@ -4,27 +4,27 @@ let eventHub const bindKey = () => { mousetrap.reset() mousetrap.bind('shift', (event, combo) => { - eventHub.$emit('shift_down', { event, combo }) + eventHub.$emit('key_shift_down', { event, combo }) return false }, 'keydown') mousetrap.bind('shift', (event, combo) => { - eventHub.$emit('shift_up', { event, combo }) + eventHub.$emit('key_shift_up', { event, combo }) return false }, 'keyup') mousetrap.bind('mod', (event, combo) => { - eventHub.$emit('mod_down', { event, combo }) + eventHub.$emit('key_mod_down', { event, combo }) return false }, 'keydown') mousetrap.bind('mod', (event, combo) => { - eventHub.$emit('mod_up', { event, combo }) + eventHub.$emit('key_mod_up', { event, combo }) return false }, 'keyup') mousetrap.bind('mod+a', (event, combo) => { - eventHub.$emit('mod+a_down', { event, combo }) + eventHub.$emit('key_mod+a_down', { event, combo }) return false }, 'keydown') mousetrap.bind('mod+a', (event, combo) => { - eventHub.$emit('mod+a_up', { event, combo }) + eventHub.$emit('key_mod+a_up', { event, combo }) return false }, 'keyup') } diff --git a/src/renderer/views/Download.vue b/src/renderer/views/Download.vue index f34614c5..8cd6fcf7 100644 --- a/src/renderer/views/Download.vue +++ b/src/renderer/views/Download.vue @@ -74,6 +74,7 @@ export default { isShiftDown: false, isModDown: false, isADown: false, + aDownTimeout: null, }, } }, @@ -129,41 +130,53 @@ export default { ...mapActions('download', ['removeTask', 'removeTasks', 'startTask', 'startTasks', 'pauseTask', 'pauseTasks']), ...mapMutations('player', ['setList']), listenEvent() { - window.eventHub.$on('shift_down', this.handle_shift_down) - window.eventHub.$on('shift_up', this.handle_shift_up) - window.eventHub.$on('mod_down', this.handle_mod_down) - window.eventHub.$on('mod_up', this.handle_mod_up) - window.eventHub.$on('mod+a_down', this.handle_mod_a_down) - window.eventHub.$on('mod+a_up', this.handle_mod_a_up) + window.eventHub.$on('key_shift_down', this.handle_key_shift_down) + window.eventHub.$on('key_shift_up', this.handle_key_shift_up) + window.eventHub.$on('key_mod_down', this.handle_key_mod_down) + window.eventHub.$on('key_mod_up', this.handle_key_mod_up) + window.eventHub.$on('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$on('key_mod+a_up', this.handle_mod_a_up) }, unlistenEvent() { - window.eventHub.$off('shift_down', this.handle_shift_down) - window.eventHub.$off('shift_up', this.handle_shift_up) - window.eventHub.$off('mod_down', this.handle_mod_down) - window.eventHub.$off('mod_up', this.handle_mod_up) - window.eventHub.$off('mod+a_down', this.handle_mod_a_down) - window.eventHub.$off('mod+a_up', this.handle_mod_a_up) + window.eventHub.$off('key_shift_down', this.handle_key_shift_down) + window.eventHub.$off('key_shift_up', this.handle_key_shift_up) + window.eventHub.$off('key_mod_down', this.handle_key_mod_down) + window.eventHub.$off('key_mod_up', this.handle_key_mod_up) + window.eventHub.$off('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$off('key_mod+a_up', this.handle_mod_a_up) }, - handle_shift_down() { + handle_key_shift_down() { if (!this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = true }, - handle_shift_up() { + handle_key_shift_up() { if (this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = false }, - handle_mod_down() { + handle_key_mod_down() { if (!this.keyEvent.isModDown) this.keyEvent.isModDown = true }, - handle_mod_up() { + handle_key_mod_up() { if (this.keyEvent.isModDown) this.keyEvent.isModDown = false }, - handle_mod_a_down() { + handle_key_mod_a_down() { if (!this.keyEvent.isADown) { + this.keyEvent.isModDown = false this.keyEvent.isADown = true this.handleSelectAllData() + if (this.keyEvent.aDownTimeout) clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = setTimeout(() => { + this.keyEvent.aDownTimeout = null + this.keyEvent.isADown = false + }, 500) } }, - handle_mod_a_up() { - if (this.keyEvent.isADown) this.keyEvent.isADown = false + handle_key_mod_a_up() { + if (this.keyEvent.isADown) { + if (this.keyEvent.aDownTimeout) { + clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = null + } + this.keyEvent.isADown = false + } }, handleDoubleClick(event, index) { if (event.target.classList.contains('select')) return diff --git a/src/renderer/views/List.vue b/src/renderer/views/List.vue index b70b30f1..a55ab001 100644 --- a/src/renderer/views/List.vue +++ b/src/renderer/views/List.vue @@ -72,6 +72,7 @@ export default { isShiftDown: false, isModDown: false, isADown: false, + aDownTimeout: null, }, } }, @@ -188,41 +189,53 @@ export default { setPlayList: 'setList', }), listenEvent() { - window.eventHub.$on('shift_down', this.handle_shift_down) - window.eventHub.$on('shift_up', this.handle_shift_up) - window.eventHub.$on('mod_down', this.handle_mod_down) - window.eventHub.$on('mod_up', this.handle_mod_up) - window.eventHub.$on('mod+a_down', this.handle_mod_a_down) - window.eventHub.$on('mod+a_up', this.handle_mod_a_up) + window.eventHub.$on('key_shift_down', this.handle_key_shift_down) + window.eventHub.$on('key_shift_up', this.handle_key_shift_up) + window.eventHub.$on('key_mod_down', this.handle_key_mod_down) + window.eventHub.$on('key_mod_up', this.handle_key_mod_up) + window.eventHub.$on('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$on('key_mod+a_up', this.handle_mod_a_up) }, unlistenEvent() { - window.eventHub.$off('shift_down', this.handle_shift_down) - window.eventHub.$off('shift_up', this.handle_shift_up) - window.eventHub.$off('mod_down', this.handle_mod_down) - window.eventHub.$off('mod_up', this.handle_mod_up) - window.eventHub.$off('mod+a_down', this.handle_mod_a_down) - window.eventHub.$off('mod+a_up', this.handle_mod_a_up) + window.eventHub.$off('key_shift_down', this.handle_key_shift_down) + window.eventHub.$off('key_shift_up', this.handle_key_shift_up) + window.eventHub.$off('key_mod_down', this.handle_key_mod_down) + window.eventHub.$off('key_mod_up', this.handle_key_mod_up) + window.eventHub.$off('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$off('key_mod+a_up', this.handle_mod_a_up) }, - handle_shift_down() { + handle_key_shift_down() { if (!this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = true }, - handle_shift_up() { + handle_key_shift_up() { if (this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = false }, - handle_mod_down() { + handle_key_mod_down() { if (!this.keyEvent.isModDown) this.keyEvent.isModDown = true }, - handle_mod_up() { + handle_key_mod_up() { if (this.keyEvent.isModDown) this.keyEvent.isModDown = false }, - handle_mod_a_down() { + handle_key_mod_a_down() { if (!this.keyEvent.isADown) { + this.keyEvent.isModDown = false this.keyEvent.isADown = true this.handleSelectAllData() + if (this.keyEvent.aDownTimeout) clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = setTimeout(() => { + this.keyEvent.aDownTimeout = null + this.keyEvent.isADown = false + }, 500) } }, - handle_mod_a_up() { - if (this.keyEvent.isADown) this.keyEvent.isADown = false + handle_key_mod_a_up() { + if (this.keyEvent.isADown) { + if (this.keyEvent.aDownTimeout) { + clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = null + } + this.keyEvent.isADown = false + } }, handleDelayShow() { this.clearDelayTimeout() diff --git a/src/renderer/views/Search.vue b/src/renderer/views/Search.vue index 354e56e9..0af3f6c4 100644 --- a/src/renderer/views/Search.vue +++ b/src/renderer/views/Search.vue @@ -82,6 +82,7 @@ export default { isShiftDown: false, isModDown: false, isADown: false, + aDownTimeout: null, }, } }, @@ -166,41 +167,53 @@ export default { getHotSearch: 'getList', }), listenEvent() { - window.eventHub.$on('shift_down', this.handle_shift_down) - window.eventHub.$on('shift_up', this.handle_shift_up) - window.eventHub.$on('mod_down', this.handle_mod_down) - window.eventHub.$on('mod_up', this.handle_mod_up) - window.eventHub.$on('mod+a_down', this.handle_mod_a_down) - window.eventHub.$on('mod+a_up', this.handle_mod_a_up) + window.eventHub.$on('key_shift_down', this.handle_key_shift_down) + window.eventHub.$on('key_shift_up', this.handle_key_shift_up) + window.eventHub.$on('key_mod_down', this.handle_key_mod_down) + window.eventHub.$on('key_mod_up', this.handle_key_mod_up) + window.eventHub.$on('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$on('key_mod+a_up', this.handle_mod_a_up) }, unlistenEvent() { - window.eventHub.$off('shift_down', this.handle_shift_down) - window.eventHub.$off('shift_up', this.handle_shift_up) - window.eventHub.$off('mod_down', this.handle_mod_down) - window.eventHub.$off('mod_up', this.handle_mod_up) - window.eventHub.$off('mod+a_down', this.handle_mod_a_down) - window.eventHub.$off('mod+a_up', this.handle_mod_a_up) + window.eventHub.$off('key_shift_down', this.handle_key_shift_down) + window.eventHub.$off('key_shift_up', this.handle_key_shift_up) + window.eventHub.$off('key_mod_down', this.handle_key_mod_down) + window.eventHub.$off('key_mod_up', this.handle_key_mod_up) + window.eventHub.$off('key_mod+a_down', this.handle_mod_a_down) + window.eventHub.$off('key_mod+a_up', this.handle_mod_a_up) }, - handle_shift_down() { + handle_key_shift_down() { if (!this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = true }, - handle_shift_up() { + handle_key_shift_up() { if (this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = false }, - handle_mod_down() { + handle_key_mod_down() { if (!this.keyEvent.isModDown) this.keyEvent.isModDown = true }, - handle_mod_up() { + handle_key_mod_up() { if (this.keyEvent.isModDown) this.keyEvent.isModDown = false }, - handle_mod_a_down() { + handle_key_mod_a_down() { if (!this.keyEvent.isADown) { + this.keyEvent.isModDown = false this.keyEvent.isADown = true this.handleSelectAllData() + if (this.keyEvent.aDownTimeout) clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = setTimeout(() => { + this.keyEvent.aDownTimeout = null + this.keyEvent.isADown = false + }, 500) } }, - handle_mod_a_up() { - if (this.keyEvent.isADown) this.keyEvent.isADown = false + handle_key_mod_a_up() { + if (this.keyEvent.isADown) { + if (this.keyEvent.aDownTimeout) { + clearTimeout(this.keyEvent.aDownTimeout) + this.keyEvent.aDownTimeout = null + } + this.keyEvent.isADown = false + } }, handleSearch(text, page) { if (text === '') return this.clearList()