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
This commit is contained in:
Araxeus
2021-12-03 14:43:30 +02:00
parent d13c9b7ca6
commit 2daee01ff7
3 changed files with 13 additions and 13 deletions

View File

@ -1,6 +1,7 @@
const mpris = require("mpris-service"); const mpris = require("mpris-service");
const { ipcMain } = require("electron"); const { ipcMain } = require("electron");
const registerCallback = require("../../providers/song-info"); const registerCallback = require("../../providers/song-info");
const getSongControls = require("../../providers/song-controls");
function setupMPRIS() { function setupMPRIS() {
const player = mpris({ const player = mpris({
@ -17,6 +18,8 @@ function setupMPRIS() {
} }
function registerMPRIS(win) { function registerMPRIS(win) {
const songControls = getSongControls(win);
const { playPause, next, previous } = songControls;
try { try {
const secToMicro = n => Math.round(Number(n) * 1e6); const secToMicro = n => Math.round(Number(n) * 1e6);
const microToSec = 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 player = setupMPRIS();
const mprisSeek = player.seeked; ipcMain.on('seeked', (_, t) => player.seeked(secToMicro(t)));
ipcMain.on('seeked', (_, t) => mprisSeek(secToMicro(t)));
let currentSeconds = 0; let currentSeconds = 0;
ipcMain.on('timeChanged', (_, t) => currentSeconds = t); ipcMain.on('timeChanged', (_, t) => currentSeconds = t);
@ -71,7 +72,7 @@ function registerMPRIS(win) {
}; };
if (songInfo.album) data['xesam:album'] = songInfo.album; if (songInfo.album) data['xesam:album'] = songInfo.album;
player.metadata = data; player.metadata = data;
mprisSeek(secToMicro(songInfo.elapsedSeconds)) player.seeked(secToMicro(songInfo.elapsedSeconds))
player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing" player.playbackStatus = songInfo.isPaused ? "Paused" : "Playing"
} }
}) })

View File

@ -4,12 +4,10 @@ const is = require("electron-is");
module.exports.setupSongControls = () => { module.exports.setupSongControls = () => {
document.addEventListener('apiLoaded', e => { document.addEventListener('apiLoaded', e => {
ipcRenderer.on("seekTo", (_, t) => e.target.seekTo(t)); ipcRenderer.on("seekTo", (_, t) => e.detail.seekTo(t));
ipcRenderer.on("seekBy", (_, t) => e.target.seekBy(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 }) }, { once: true, passive: true })
if (is.linux() && config.plugins.isEnabled('shortcuts')) { // MPRIS Enabled
document.querySelector('video').addEventListener('seeked', () => ipcRenderer.send('seeked', v.currentTime));
}
}; };

View File

@ -1,5 +1,5 @@
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
const is = require('electron-is');
const { getImage } = require("./song-info"); const { getImage } = require("./song-info");
const config = require("../config"); const config = require("../config");
@ -18,7 +18,8 @@ const srcChangedEvent = new CustomEvent('srcChanged');
module.exports = () => { module.exports = () => {
document.addEventListener('apiLoaded', apiEvent => { document.addEventListener('apiLoaded', apiEvent => {
if (config.plugins.isEnabled('tuna-obs')) { if (config.plugins.isEnabled('tuna-obs') ||
(is.linux() && config.plugins.isEnabled('shortcuts'))) {
setupTimeChangeListener(); setupTimeChangeListener();
} }
const video = $('video'); const video = $('video');