-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path06-better-management-of-MPRIS.patch
161 lines (158 loc) · 6 KB
/
06-better-management-of-MPRIS.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
From 16026d3b586904af7d8ca32248abe0be9eddaa84 Mon Sep 17 00:00:00 2001
From: josselinonduty <[email protected]>
Date: Fri, 31 Jan 2025 11:55:37 +0100
Subject: [PATCH] fix: update deps for mpris patch - @jellybrick/mpris-service
---
build/main.js | 72 ++++++++++++++++++++++++++++++++++++++++++---------
package.json | 1 +
2 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/build/main.js b/build/main.js
index 9219f4f..34be768 100644
--- a/build/main.js
+++ b/build/main.js
@@ -88,6 +88,10 @@
external_semver_default = __webpack_require__.n(
external_semver_namespaceObject
);
+ const external_electron_mpris_namespaceObject = require("@jellybrick/mpris-service");
+ var external_electron_mpris_default = __webpack_require__.n(
+ external_electron_mpris_namespaceObject
+ );
function isPlatform(platform) {
switch (platform) {
case PLATFORM.WINDOWS:
@@ -1188,8 +1192,9 @@
};
};
let MediaService = class extends external_events_namespaceObject.EventEmitter {
- constructor(ipc, user) {
+ constructor(ipc, user, app) {
super(),
+ (this.app = app),
(this.smtc = null),
(this.track = {}),
(this.player = {}),
@@ -1197,6 +1202,11 @@
(this.debounceOptions = { leading: !0, maxWait: 500 }),
(this.ipc = ipc),
(this.user = user),
+ (this.mprisPlayer = new external_electron_mpris_namespaceObject({
+ name: 'deezer',
+ identity: 'Deezer',
+ supportedInterfaces: ['player']
+ })),
isPlatform(PLATFORM.LINUX) &&
(this.user.addListener(UserEvents.LoggedIn, () => {
this.start();
@@ -1204,6 +1214,19 @@
this.user.addListener(UserEvents.LoggedOut, () => {
this.stop();
}));
+ this.initMprisPlayerControls();
+ }
+ initMprisPlayerControls() {
+ // Events => ['raise', 'quit', 'next', 'previous', 'pause', 'playpause', 'stop', 'play', 'seek', 'position', 'open', 'volume', 'loopStatus', 'shuffle'];
+ this.mprisPlayer.on('play', this.play.bind(this));
+ this.mprisPlayer.on('pause', this.pause.bind(this));
+ this.mprisPlayer.on('playpause', () => this.player.state === 'playing' ? this.pause() : this.play());
+ this.mprisPlayer.on('stop', this.stop.bind(this));
+ this.mprisPlayer.on('next', this.next.bind(this));
+ this.mprisPlayer.on('previous', this.prev.bind(this));
+ this.mprisPlayer.on('shuffle', this.setSuffle.bind(this));
+ this.mprisPlayer.on('loopStatus', this.setRepeatMode.bind(this));
+ this.mprisPlayer.on('raise', () => this.app.getWindow().show())
}
play() {
this.ipc.send("channel-player-media-control", MediaPlayerControl.Play);
@@ -1231,11 +1254,23 @@
}
setTrackInfo(track) {
(this.track = Object.assign(this.track, track)),
- this.emit(MediaEvents.TrackUpdated, this.track);
+ this.emit(MediaEvents.TrackUpdated, this.track),
+ (this.mprisPlayer.metadata = {
+ 'mpris:trackid': this.mprisPlayer.objectPath('track/0'),
+ 'mpris:artUrl': track.coverUrl,
+ 'xesam:title': track.title,
+ 'xesam:album': track.album,
+ 'xesam:artist': [track.artist]
+ });
}
setPlayerInfo(player) {
(this.player = Object.assign(this.player, player)),
- this.emit(MediaEvents.PlayerUpdated, this.player);
+ this.emit(MediaEvents.PlayerUpdated, this.player),
+ (this.mprisPlayer.playbackStatus =
+ this.player.state === 'playing'
+ ? external_electron_mpris_namespaceObject.PLAYBACK_STATUS_PLAYING
+ : external_electron_mpris_namespaceObject.PLAYBACK_STATUS_PAUSED
+ );
}
getTrackInfo() {
return this.track;
@@ -1295,7 +1330,11 @@
1,
(0, external_inversify_namespaceObject.inject)(SERVICE_USER)
),
- MediaService_metadata("design:paramtypes", [Object, Object]),
+ MediaService_param(
+ 2,
+ (0, external_inversify_namespaceObject.inject)(SERVICE_APPLICATION)
+ ),
+ MediaService_metadata("design:paramtypes", [Object, Object, Object]),
],
MediaService
);
@@ -2733,14 +2772,20 @@
const PlayerIpc_ipc = main_di.get(SERVICE_IPC),
media = main_di.get(SERVICE_MEDIA),
powerSave = main_di.get(SERVICE_POWER_SAVE);
- PlayerIpc_ipc.on(
- "channel-player-state-update",
- external_lodash_debounce_default()((event, state) => {
- media.setPlayerInfo({ state }),
- state === MediaPlayerState.Playing
- ? powerSave.start()
- : powerSave.stop();
- }, 3e3)
+ var powerSaveTimeoutId;
+ PlayerIpc_ipc.on(
+ "channel-player-state-update",
+ (event, state) => {
+ media.setPlayerInfo({ state }),
+ clearTimeout(powerSaveTimeoutId),
+ powerSaveTimeoutId = setTimeout(
+ () => {
+ state === MediaPlayerState.Playing
+ ? powerSave.start()
+ : powerSave.stop();
+ }, 3e3
+ );
+ }
),
PlayerIpc_ipc.on(
"channel-player-track-update",
@@ -2828,6 +2873,9 @@
"autoplay-policy",
"no-user-gesture-required"
),
+ external_electron_namespaceObject.app.commandLine.appendSwitch(
+ "disable-features", "HardwareMediaKeyHandling"
+ ),
external_electron_namespaceObject.app.on(
"second-instance",
(event, argv) => {
diff --git a/package.json b/package.json
index 290f49a..394b4f4 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"main": "build/main.js",
"dependencies": {
"@electron/remote": "2.1.2",
+ "@jellybrick/mpris-service": "2.1.5",
"electron-log": "^5.1.2",
"electron-settings": "4.0.4",
"electron-updater": "^6.1.8",
--
2.43.0