From c82f30480abf24204578a94dcd8d18e32b3f6004 Mon Sep 17 00:00:00 2001 From: qier222 Date: Mon, 28 Dec 2020 23:51:09 +0800 Subject: [PATCH] fix: player will play/pause when user are typing in search box --- package.json | 1 - src/App.vue | 26 +++++++++++++------------- src/electron/menu.js | 1 - yarn.lock | 5 ----- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 6e3352c..239b618 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "vue": "^2.6.11", "vue-analytics": "^5.22.1", "vue-electron": "^1.0.6", - "vue-global-events": "^1.2.1", "vue-i18n": "^8.22.0", "vue-router": "^3.4.3", "vue-slider-component": "^3.2.5", diff --git a/src/App.vue b/src/App.vue index 609437c..755b000 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,7 +18,6 @@ " /> - @@ -30,7 +29,6 @@ import ModalNewPlaylist from "./components/ModalNewPlaylist.vue"; import Navbar from "./components/Navbar.vue"; import Player from "./components/Player.vue"; import Toast from "./components/Toast.vue"; -import GlobalEvents from "vue-global-events"; import { ipcRenderer } from "./electron/ipcRenderer"; export default { @@ -38,7 +36,6 @@ export default { components: { Navbar, Player, - GlobalEvents, Toast, ModalAddTrackToPlaylist, ModalNewPlaylist, @@ -52,16 +49,16 @@ export default { if (this.isElectron) { ipcRenderer(this); } + window.addEventListener("keydown", this.handleKeydown); }, methods: { - play(e) { - e.preventDefault(); - this.$refs.player.play(); - }, - globalEventFilter(event) { - if (event.target.tagName === "INPUT") return false; - if (this.$route.name === "mv") return false; - return true; + handleKeydown(e) { + if (e.code === "Space") { + if (e.target.tagName === "INPUT") return false; + if (this.$route.name === "mv") return false; + e.preventDefault(); + this.$refs.player.play(); + } }, }, }; @@ -96,11 +93,14 @@ export default { } #app { + width: 100%; + transition: all 0.4s; +} +#app, +input { font-family: "Barlow", -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif; - width: 100%; - transition: all 0.4s; } body { background-color: var(--color-body-bg); diff --git a/src/electron/menu.js b/src/electron/menu.js index 7965400..b04213e 100644 --- a/src/electron/menu.js +++ b/src/electron/menu.js @@ -69,7 +69,6 @@ export function createMenu(win) { submenu: [ { label: "Play", - accelerator: "Space", click: () => { win.webContents.send("play"); }, diff --git a/yarn.lock b/yarn.lock index 2e50496..98470f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11094,11 +11094,6 @@ vue-eslint-parser@^7.0.0: esquery "^1.0.1" lodash "^4.17.15" -vue-global-events@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/vue-global-events/-/vue-global-events-1.2.1.tgz#4c1398a1f67854c73290f5c1cedb5109116c2b50" - integrity sha512-035Su/+5GUFnj9potJThJXu9DnayRKSENbuBw5k5sMa6hetiY+6Yu+5zUtPXT4X0S9y8tX7uSxGZJMMYiqhFfg== - vue-hot-reload-api@^2.3.0: version "2.3.4" resolved "https://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz?cache=0&sync_timestamp=1589682714858&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-hot-reload-api%2Fdownload%2Fvue-hot-reload-api-2.3.4.tgz#532955cc1eb208a3d990b3a9f9a70574657e08f2"