mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix: mpris was not registering itself before.
Sorry I missed that somehow, because playerctl controls were working. That was because of chromium was also registering itself for mpris.
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, () => {
|
||||||
@ -26,18 +28,41 @@ function registerShortcuts(win, options) {
|
|||||||
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
registerCallback(songInfo => {
|
||||||
|
player.metadata = {
|
||||||
|
'mpris:length': songInfo.songDuration * 60 * 1000 * 1000, // In microseconds
|
||||||
|
'mpris:artUrl': songInfo.imageSrc,
|
||||||
|
'xesam:title': songInfo.title,
|
||||||
|
'xesam:artist': songInfo.artist
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if (is.linux()) {
|
if (is.linux()) {
|
||||||
try {
|
try {
|
||||||
const player = setupMPRIS();
|
const MPRISPlayer = setupMPRIS();
|
||||||
|
player = MPRISPlayer
|
||||||
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);
|
console.log('Event:', "play", arguments);
|
||||||
player.on("previous", previous);
|
player.playbackStatus = 'Playing';
|
||||||
|
playPause()
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("pause", () => {
|
||||||
|
console.log('Event:', "pause", arguments);
|
||||||
|
player.playbackStatus = 'Paused';
|
||||||
|
playPause()
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("next", () => {
|
||||||
|
next()
|
||||||
|
});
|
||||||
|
MPRISPlayer.on("previous", () => {
|
||||||
|
previous()
|
||||||
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Error in MPRIS", e);
|
console.warn("Error in MPRIS", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user