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

Add mpris support with cherry picked commit from previous PR https://github.com/th-ch/youtube-music/pull/394 #395

Merged
merged 1 commit into from
Sep 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"electron-updater": "^4.3.10",
"filenamify": "^4.3.0",
"md5": "^2.3.0",
"mpris-service": "^2.1.2",
"node-fetch": "^2.6.1",
"node-notifier": "^9.0.1",
"ytdl-core": "^4.9.1",
Expand Down
17 changes: 17 additions & 0 deletions plugins/shortcuts/back.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { globalShortcut } = require("electron");
const electronLocalshortcut = require("electron-localshortcut");
const { setupMPRIS } = require("./mpris");

const getSongControls = require("../../providers/song-controls");

Expand All @@ -25,6 +26,22 @@ function registerShortcuts(win, options) {
_registerLocalShortcut(win, "CommandOrControl+F", search);
_registerLocalShortcut(win, "CommandOrControl+L", search);

if (is.linux()) {
try {
const player = setupMPRIS();

player.on("raise", () => {
win.setSkipTaskbar(false);
win.show();
});
player.on("playpause", playPause);
player.on("next", next);
player.on("previous", previous);
} catch (e) {
console.warn("Error in MPRIS", e);
}
}

const { global, local } = options;
(global || []).forEach(({ shortcut, action }) => {
console.debug("Registering global shortcut", shortcut, ":", action);
Expand Down
19 changes: 19 additions & 0 deletions plugins/shortcuts/mpris.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mpris = require("mpris-service");

function setupMPRIS() {
const player = mpris({
name: "youtube-music",
identity: "YouTube Music",
canRaise: true,
supportedUriSchemes: ["https"],
supportedMimeTypes: ["audio/mpeg"],
supportedInterfaces: ["player"],
desktopEntry: "youtube-music",
});

return player;
}

module.exports = {
setupMPRIS,
};
Loading