Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit 4391d56

Browse files
committed
re-implement mpris events and delete executable
1 parent c1acc04 commit 4391d56

File tree

3 files changed

+92
-51
lines changed

3 files changed

+92
-51
lines changed

dbus.js

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,76 @@ module.exports = function(appName){
2727
});
2828
}
2929
}
30+
class DBusMPRIS extends EventEmitter{
31+
constructor(appName) {
32+
super();
33+
this._player = Player({
34+
name: appName,
35+
identity: appName,
36+
supportedUriSchemes: ['http'],
37+
supportedMimeTypes: ['application/www-url'],
38+
desktopEntry: appName
39+
});
40+
}
41+
on(name, func){
42+
this._player.on(name, func);
43+
}
44+
set position(pos) {
45+
if (pos !== this.position) this._player.position = pos;
46+
}
47+
get position() {
48+
return this._player.position;
49+
}
50+
set playbackStatus(stat){
51+
if (stat !== this.playbackStatus) this._player.playbackStatus = stat;
52+
}
53+
get playbackStatus(){
54+
return this._player.playbackStatus;
55+
}
56+
set volume(vol) {
57+
if (vol !== this.volume) this._player.volume = vol;
58+
}
59+
get volume() {
60+
return this._player.volume;
61+
}
62+
set shuffle(shuff){
63+
if (shuff !== this.shuffle) this._player.shuffle = shuff;
64+
}
65+
get shuffle(){
66+
return this._player.shuffle;
67+
}
68+
set repeat(rep){
69+
if (rep !== this.repeat) this._player.repeat = rep;
70+
}
71+
get repeat() {
72+
return this._player.repeat;
73+
}
74+
set metadata (met) {
75+
if (
76+
(met && !this.metadata) ||
77+
(this.metadata && this.metadata['xesam:url'] !== met['xesam:url'])
78+
) {
79+
this._player.metadata = met;
80+
}
81+
}
82+
get metadata(){
83+
return this._player.metadata;
84+
}
85+
objectPath(str) {
86+
return this._player.objectPath(str);
87+
}
88+
}
3089
return {
3190
mediakeys: new DBusMediaKeys(bus),
3291
notifications: {
3392
notify: (summary, body, icon) => {
34-
console.log(summary, body, icon);
93+
console.log(`notify('${summary}','${body.replace(/\n/g, '\\n')}','${icon}')`);
3594
notification.summary = summary;
3695
notification.body = body;
3796
notification.icon = icon;
3897
notification.push();
3998
}
4099
},
41-
mpris: Player({
42-
name: appName,
43-
identity: appName,
44-
supportedUriSchemes: ['http'],
45-
supportedMimeTypes: ['application/www-url'],
46-
desktopEntry: appName
47-
})
100+
mpris: new DBusMPRIS(appName)
48101
};
49102
};

spotifywebplayer

Lines changed: 0 additions & 6 deletions
This file was deleted.

windows/spotify/controller.js

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@ module.exports = (function() {
88
const dbus = props.dbus;
99
updateMetadata = function(info){
1010
if (dbus && info.track){
11-
if (!dbus.mpris.metadata || (dbus.mpris.metadata && dbus.mpris.metadata['xesam:url'] !== info.track.url)) {
12-
dbus.mpris.metadata = {
13-
'mpris:trackid': dbus.mpris.objectPath('track/' + info.track.trackNumber),
14-
'mpris:length': info.track.length,
15-
'mpris:artUrl': info.track.art,
16-
'xesam:title': info.track.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles
17-
'xesam:album': info.track.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names
18-
'xesam:artist': info.track.artists,
19-
'xesam:url': info.track.url
20-
};
21-
}
22-
if (dbus.mpris.volume != info.volume) dbus.mpris.volume = info.volume;
23-
if (info.track.position && dbus.mpris.position != info.track.position) dbus.mpris.position = info.track.position;
24-
if (dbus.mpris.playbackStatus != info.status) dbus.mpris.playbackStatus = info.status;
25-
if (dbus.mpris.shuffle != info.shuffle) dbus.mpris.shuffle = info.shuffle;
26-
if (dbus.mpris.repeat != info.repeat) dbus.mpris.repeat = info.repeat;
11+
dbus.mpris.metadata = {
12+
'mpris:trackid': dbus.mpris.objectPath('track/' + info.track.trackNumber),
13+
'mpris:length': info.track.length,
14+
'mpris:artUrl': info.track.art,
15+
'xesam:title': info.track.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles
16+
'xesam:album': info.track.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names
17+
'xesam:artist': info.track.artists,
18+
'xesam:url': info.track.url
19+
};
20+
dbus.mpris.volume = info.volume;
21+
dbus.mpris.position = info.track.position;
22+
dbus.mpris.playbackStatus = info.status;
23+
dbus.mpris.shuffle = info.shuffle;
24+
dbus.mpris.repeat = info.repeat;
2725
}
2826
}
2927
class Controller extends EventEmitter {
@@ -114,28 +112,24 @@ module.exports = (function() {
114112
});
115113

116114
if (dbus) {
117-
console.log('setup!');
118-
dbus.mediakeys.on('Play', () => {
119-
console.log('RECEIVED!!!');
120-
this.playPause();
121-
});
122-
dbus.mediakeys.on('Stop', this.stop);
123-
dbus.mediakeys.on('Next', this.next);
124-
dbus.mediakeys.on('Previous', this.previous);
115+
dbus.mediakeys.on('Play', () => this.playPause());
116+
dbus.mediakeys.on('Stop', () => this.stop());
117+
dbus.mediakeys.on('Next', () => this.next());
118+
dbus.mediakeys.on('Previous', () => this.previous());
125119

126-
dbus.mpris.on('Play', this.play);
127-
dbus.mpris.on('PlayPause', this.playPause);
128-
dbus.mpris.on('Next', this.next);
129-
dbus.mpris.on('Previous', this.previous);
130-
dbus.mpris.on('Stop', this.stop);
131-
dbus.mpris.on('OpenUri', (e) => {if(e.uri.indexOf('spotify:track:') > -1){this.playTrack(e.uri)}});
132-
dbus.mpris.on('Quit', () => { this.emit('Quit'); });
133-
dbus.mpris.on('Raise', () => { this.emit('Raise'); });
134-
dbus.mpris.on('Volume', (volume) => {this.setVolume(volume);});
135-
dbus.mpris.on('Shuffle', (shuffle) => {this.setShuffle(shuffle);});
136-
dbus.mpris.on('Loop', (loop) => {this.setLoop(loop);});
137-
dbus.mpris.on('Seek', (mms) => {this.seek(mms.delta/1000);});
138-
dbus.mpris.on('SetPosition', (track,pos) => {console.log('SetPosition not yet implemented')});
120+
dbus.mpris.on('play', () => this.play());
121+
dbus.mpris.on('playpause', () => this.playPause());
122+
dbus.mpris.on('next', () => this.next());
123+
dbus.mpris.on('previous', this.previous);
124+
dbus.mpris.on('stop', this.stop);
125+
dbus.mpris.on('openuri', (e) => {if(e.uri.indexOf('spotify:track:') > -1){this.playTrack(e.uri)}});
126+
dbus.mpris.on('quit', () => { this.emit('Quit'); });
127+
dbus.mpris.on('raise', () => { this.emit('Raise'); });
128+
dbus.mpris.on('volume', (volume) => {this.setVolume(volume);});
129+
dbus.mpris.on('shuffle', (shuffle) => {this.setShuffle(shuffle);});
130+
dbus.mpris.on('loopStatus', (loop) => {this.setLoop(loop);});
131+
dbus.mpris.on('seek', (mms) => {this.seek(mms.delta/1000);});
132+
dbus.mpris.on('position', (track,pos) => {console.log('SetPosition not yet implemented')});
139133
}
140134
}
141135
pause() {

0 commit comments

Comments
 (0)