Skip to content

Commit e255777

Browse files
committed
Add mpris support
1 parent fe0f213 commit e255777

File tree

4 files changed

+214
-3
lines changed

4 files changed

+214
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"electron-updater": "^4.3.10",
8383
"filenamify": "^4.3.0",
8484
"md5": "^2.3.0",
85+
"mpris-service": "^2.1.2",
8586
"node-fetch": "^2.6.1",
8687
"node-notifier": "^9.0.1",
8788
"ytdl-core": "^4.9.1",

plugins/shortcuts/back.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { globalShortcut } = require("electron");
22
const electronLocalshortcut = require("electron-localshortcut");
3+
const { setupMPRIS } = require("./mpris");
34

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

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

29+
if (is.linux()) {
30+
try {
31+
const player = setupMPRIS();
32+
33+
player.on("raise", () => {
34+
win.setSkipTaskbar(false);
35+
win.show();
36+
});
37+
player.on("playpause", playPause);
38+
player.on("next", next);
39+
player.on("previous", previous);
40+
} catch (e) {
41+
console.warn("Error in MPRIS", e);
42+
}
43+
}
44+
2845
const { global, local } = options;
2946
(global || []).forEach(({ shortcut, action }) => {
3047
console.debug("Registering global shortcut", shortcut, ":", action);

plugins/shortcuts/mpris.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const mpris = require("mpris-service");
2+
3+
function setupMPRIS() {
4+
const player = mpris({
5+
name: "youtube-music",
6+
identity: "YouTube Music",
7+
canRaise: true,
8+
supportedUriSchemes: ["https"],
9+
supportedMimeTypes: ["audio/mpeg"],
10+
supportedInterfaces: ["player"],
11+
desktopEntry: "youtube-music",
12+
});
13+
14+
return player;
15+
}
16+
17+
module.exports = {
18+
setupMPRIS,
19+
};

0 commit comments

Comments
 (0)