Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mpris bugs - follows #480 #509

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions plugins/shortcuts/mpris.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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"
}
})
Expand Down
12 changes: 5 additions & 7 deletions providers/song-controls-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
5 changes: 3 additions & 2 deletions providers/song-info-front.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ipcRenderer } = require("electron");

const is = require('electron-is');
const { getImage } = require("./song-info");

const config = require("../config");
Expand All @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions youtube-music.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}