mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
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:
@ -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"
|
||||
}
|
||||
})
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
@ -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');
|
||||
|
||||
Reference in New Issue
Block a user