From 7a96d7dfeb66de5c0194f2759607a336b6de681b Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 9 Oct 2023 15:13:12 -0400 Subject: [PATCH 1/3] [4857] Space play/pause music in queue view --- src/controllers/playback/queue/index.js | 42 +++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/controllers/playback/queue/index.js b/src/controllers/playback/queue/index.js index 602135a7946..beae60dd8b5 100644 --- a/src/controllers/playback/queue/index.js +++ b/src/controllers/playback/queue/index.js @@ -1,19 +1,49 @@ -import RemoteControl from '../../../components/remotecontrol/remotecontrol'; -import libraryMenu from '../../../scripts/libraryMenu'; -import '../../../elements/emby-button/emby-button'; +import RemoteControl from "../../../components/remotecontrol/remotecontrol"; +import { playbackManager } from "../../../components/playback/playbackmanager"; +import libraryMenu from "../../../scripts/libraryMenu"; +import "../../../elements/emby-button/emby-button"; export default function (view) { const remoteControl = new RemoteControl(); - remoteControl.init(view, view.querySelector('.remoteControlContent')); - view.addEventListener('viewshow', function () { + remoteControl.init(view, view.querySelector(".remoteControlContent")); + + let currentPlayer; + + function onKeyDown(e) { + if (e.keyCode === 32 && e.target.tagName !== "BUTTON") { + playbackManager.playPause(currentPlayer); + e.preventDefault(); + e.stopPropagation(); + } + } + + function releaseCurrentPlayer() { + const player = currentPlayer; + if (player) currentPlayer = null; + } + + function bindToPlayer(player) { + if (player !== currentPlayer) { + releaseCurrentPlayer(); + currentPlayer = player; + if (!player) return; + } + } + + view.addEventListener("viewshow", function () { libraryMenu.setTransparentMenu(true); + bindToPlayer(playbackManager.getCurrentPlayer()); + document.addEventListener("keydown", onKeyDown); if (remoteControl) { remoteControl.onShow(); } }); - view.addEventListener('viewbeforehide', function () { + + view.addEventListener("viewbeforehide", function () { libraryMenu.setTransparentMenu(false); + document.removeEventListener("keydown", onKeyDown); + releaseCurrentPlayer(); if (remoteControl) { remoteControl.destroy(); From bf5e52571493b8ca01b38be1cae067427e6a7e27 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 9 Oct 2023 17:40:31 -0400 Subject: [PATCH 2/3] Fix lint issues --- src/controllers/playback/queue/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/playback/queue/index.js b/src/controllers/playback/queue/index.js index beae60dd8b5..de2188feb3e 100644 --- a/src/controllers/playback/queue/index.js +++ b/src/controllers/playback/queue/index.js @@ -1,16 +1,16 @@ -import RemoteControl from "../../../components/remotecontrol/remotecontrol"; -import { playbackManager } from "../../../components/playback/playbackmanager"; -import libraryMenu from "../../../scripts/libraryMenu"; -import "../../../elements/emby-button/emby-button"; +import RemoteControl from '../../../components/remotecontrol/remotecontrol'; +import { playbackManager } from '../../../components/playback/playbackmanager'; +import libraryMenu from '../../../scripts/libraryMenu'; +import '../../../elements/emby-button/emby-button'; export default function (view) { const remoteControl = new RemoteControl(); - remoteControl.init(view, view.querySelector(".remoteControlContent")); + remoteControl.init(view, view.querySelector('.remoteControlContent')); let currentPlayer; function onKeyDown(e) { - if (e.keyCode === 32 && e.target.tagName !== "BUTTON") { + if (e.keyCode === 32 && e.target.tagName !== 'BUTTON') { playbackManager.playPause(currentPlayer); e.preventDefault(); e.stopPropagation(); @@ -30,19 +30,19 @@ export default function (view) { } } - view.addEventListener("viewshow", function () { + view.addEventListener('viewshow', function () { libraryMenu.setTransparentMenu(true); bindToPlayer(playbackManager.getCurrentPlayer()); - document.addEventListener("keydown", onKeyDown); + document.addEventListener('keydown', onKeyDown); if (remoteControl) { remoteControl.onShow(); } }); - view.addEventListener("viewbeforehide", function () { + view.addEventListener('viewbeforehide', function () { libraryMenu.setTransparentMenu(false); - document.removeEventListener("keydown", onKeyDown); + document.removeEventListener('keydown', onKeyDown); releaseCurrentPlayer(); if (remoteControl) { From 68362f4a1f7064a2ab5c17836116cabc46efb0e1 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 16 Oct 2023 16:21:35 -0400 Subject: [PATCH 3/3] Remove line that returns early for no reason --- src/controllers/playback/queue/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controllers/playback/queue/index.js b/src/controllers/playback/queue/index.js index de2188feb3e..7741b87dde4 100644 --- a/src/controllers/playback/queue/index.js +++ b/src/controllers/playback/queue/index.js @@ -26,7 +26,6 @@ export default function (view) { if (player !== currentPlayer) { releaseCurrentPlayer(); currentPlayer = player; - if (!player) return; } }