From 2daee01ff78f01cb87f14748381f0c41191c7cbe Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 3 Dec 2021 14:43:30 +0200 Subject: [PATCH 1/2] Fix bugs from bad merge conflict solving -fix missing songControls -use player.seeked directly -fix 'seeked' event listener -fix e.target instead of e.detail in apiLoaded event -fix document.querySelector('video') before apiLoaded -setup timeChange Listener if linux+shortcuts enabled --- plugins/shortcuts/mpris.js | 9 +++++---- providers/song-controls-front.js | 12 +++++------- providers/song-info-front.js | 5 +++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/shortcuts/mpris.js b/plugins/shortcuts/mpris.js index e6c6539f..4be81da4 100644 --- a/plugins/shortcuts/mpris.js +++ b/plugins/shortcuts/mpris.js @@ -1,6 +1,7 @@ const mpris = require("mpris-service"); const { ipcMain } = require("electron"); const registerCallback = require("../../providers/song-info"); +const getSongControls = require("../../providers/song-controls"); function setupMPRIS() { const player = mpris({ @@ -17,6 +18,8 @@ function setupMPRIS() { } function registerMPRIS(win) { + const songControls = getSongControls(win); + const { playPause, next, previous } = songControls; try { const secToMicro = n => Math.round(Number(n) * 1e6); const microToSec = n => Math.round(Number(n) / 1e6); @@ -26,9 +29,7 @@ function registerMPRIS(win) { const player = setupMPRIS(); - const mprisSeek = player.seeked; - - ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t))); + ipcMain.on('seeked', (_, t) => player.seeked(secToMicro(t))); let currentSeconds = 0; ipcMain.on('timeChanged', (_, t) => currentSeconds = t); @@ -71,7 +72,7 @@ function registerMPRIS(win) { }; if (songInfo.album) data['xesam:album'] = songInfo.album; player.metadata = data; - mprisSeek(secToMicro(songInfo.elapsedSeconds)) + player.seeked(secToMicro(songInfo.elapsedSeconds)) player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing" } }) diff --git a/providers/song-controls-front.js b/providers/song-controls-front.js index 19031388..07c50542 100644 --- a/providers/song-controls-front.js +++ b/providers/song-controls-front.js @@ -4,12 +4,10 @@ const is = require("electron-is"); module.exports.setupSongControls = () => { document.addEventListener('apiLoaded', e => { - ipcRenderer.on("seekTo", (_, t) => e.target.seekTo(t)); - ipcRenderer.on("seekBy", (_, t) => e.target.seekBy(t)); - + ipcRenderer.on("seekTo", (_, t) => e.detail.seekTo(t)); + ipcRenderer.on("seekBy", (_, t) => e.detail.seekBy(t)); + if (is.linux() && config.plugins.isEnabled('shortcuts')) { // MPRIS Enabled + document.querySelector('video').addEventListener('seeked', v => ipcRenderer.send('seeked', v.target.currentTime)); + } }, { once: true, passive: true }) - - if (is.linux() && config.plugins.isEnabled('shortcuts')) { // MPRIS Enabled - document.querySelector('video').addEventListener('seeked', () => ipcRenderer.send('seeked', v.currentTime)); - } }; diff --git a/providers/song-info-front.js b/providers/song-info-front.js index 6e0349b1..368d3958 100644 --- a/providers/song-info-front.js +++ b/providers/song-info-front.js @@ -1,5 +1,5 @@ const { ipcRenderer } = require("electron"); - +const is = require('electron-is'); const { getImage } = require("./song-info"); const config = require("../config"); @@ -18,7 +18,8 @@ const srcChangedEvent = new CustomEvent('srcChanged'); module.exports = () => { document.addEventListener('apiLoaded', apiEvent => { - if (config.plugins.isEnabled('tuna-obs')) { + if (config.plugins.isEnabled('tuna-obs') || + (is.linux() && config.plugins.isEnabled('shortcuts'))) { setupTimeChangeListener(); } const video = $('video'); From c5c2d5b74c53603b606e1d37423f85e2193c1fde Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 3 Dec 2021 16:56:51 +0200 Subject: [PATCH 2/2] Hide cast button which doesn't work --- youtube-music.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/youtube-music.css b/youtube-music.css index 67a74dc0..9a36c00c 100644 --- a/youtube-music.css +++ b/youtube-music.css @@ -34,3 +34,8 @@ img { -webkit-user-select: none; user-select: none; } + +/* Hide cast button which doesn't work */ +ytmusic-cast-button { + display: none !important; +}