mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
Merge pull request #431 from itzmanish/fix/mpris
fix: mpris instance not registering itself and media controls
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
const { globalShortcut } = require("electron");
|
const { globalShortcut } = require("electron");
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
const electronLocalshortcut = require("electron-localshortcut");
|
const electronLocalshortcut = require("electron-localshortcut");
|
||||||
|
|
||||||
const getSongControls = require("../../providers/song-controls");
|
const getSongControls = require("../../providers/song-controls");
|
||||||
const { setupMPRIS } = require("./mpris");
|
const { setupMPRIS } = require("./mpris");
|
||||||
|
const registerCallback = require("../../providers/song-info");
|
||||||
|
|
||||||
|
let player;
|
||||||
|
|
||||||
function _registerGlobalShortcut(webContents, shortcut, action) {
|
function _registerGlobalShortcut(webContents, shortcut, action) {
|
||||||
globalShortcut.register(shortcut, () => {
|
globalShortcut.register(shortcut, () => {
|
||||||
@ -29,18 +31,50 @@ function registerShortcuts(win, options) {
|
|||||||
|
|
||||||
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
registerCallback(songInfo => {
|
||||||
|
if (player) {
|
||||||
|
player.metadata = {
|
||||||
|
'mpris:length': songInfo.songDuration * 60 * 1000 * 1000, // In microseconds
|
||||||
|
'mpris:artUrl': songInfo.imageSrc,
|
||||||
|
'xesam:title': songInfo.title,
|
||||||
|
'xesam:artist': songInfo.artist
|
||||||
|
};
|
||||||
|
if (!songInfo.isPaused) {
|
||||||
|
player.playbackStatus = "Playing"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if (is.linux()) {
|
if (is.linux()) {
|
||||||
try {
|
try {
|
||||||
const player = setupMPRIS();
|
const MPRISPlayer = setupMPRIS();
|
||||||
|
|
||||||
player.on("raise", () => {
|
MPRISPlayer.on("raise", () => {
|
||||||
win.setSkipTaskbar(false);
|
win.setSkipTaskbar(false);
|
||||||
win.show();
|
win.show();
|
||||||
});
|
});
|
||||||
player.on("playpause", playPause);
|
MPRISPlayer.on("play", () => {
|
||||||
player.on("next", next);
|
if (MPRISPlayer.playbackStatus !== 'Playing') {
|
||||||
player.on("previous", previous);
|
MPRISPlayer.playbackStatus = 'Playing';
|
||||||
|
playPause()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("pause", () => {
|
||||||
|
if (MPRISPlayer.playbackStatus !== 'Paused') {
|
||||||
|
MPRISPlayer.playbackStatus = 'Paused';
|
||||||
|
playPause()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("next", () => {
|
||||||
|
next()
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("previous", () => {
|
||||||
|
previous()
|
||||||
|
});
|
||||||
|
|
||||||
|
player = MPRISPlayer
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Error in MPRIS", e);
|
console.warn("Error in MPRIS", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user