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

Commit

Permalink
re-implement mpris events and delete executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Quacky2200 committed Jan 14, 2017
1 parent c1acc04 commit 4391d56
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 51 deletions.
69 changes: 61 additions & 8 deletions dbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,76 @@ module.exports = function(appName){
});
}
}
class DBusMPRIS extends EventEmitter{
constructor(appName) {
super();
this._player = Player({
name: appName,
identity: appName,
supportedUriSchemes: ['http'],
supportedMimeTypes: ['application/www-url'],
desktopEntry: appName
});
}
on(name, func){
this._player.on(name, func);
}
set position(pos) {
if (pos !== this.position) this._player.position = pos;
}
get position() {
return this._player.position;
}
set playbackStatus(stat){
if (stat !== this.playbackStatus) this._player.playbackStatus = stat;
}
get playbackStatus(){
return this._player.playbackStatus;
}
set volume(vol) {
if (vol !== this.volume) this._player.volume = vol;
}
get volume() {
return this._player.volume;
}
set shuffle(shuff){
if (shuff !== this.shuffle) this._player.shuffle = shuff;
}
get shuffle(){
return this._player.shuffle;
}
set repeat(rep){
if (rep !== this.repeat) this._player.repeat = rep;
}
get repeat() {
return this._player.repeat;
}
set metadata (met) {
if (
(met && !this.metadata) ||
(this.metadata && this.metadata['xesam:url'] !== met['xesam:url'])
) {
this._player.metadata = met;
}
}
get metadata(){
return this._player.metadata;
}
objectPath(str) {
return this._player.objectPath(str);
}
}
return {
mediakeys: new DBusMediaKeys(bus),
notifications: {
notify: (summary, body, icon) => {
console.log(summary, body, icon);
console.log(`notify('${summary}','${body.replace(/\n/g, '\\n')}','${icon}')`);
notification.summary = summary;
notification.body = body;
notification.icon = icon;
notification.push();
}
},
mpris: Player({
name: appName,
identity: appName,
supportedUriSchemes: ['http'],
supportedMimeTypes: ['application/www-url'],
desktopEntry: appName
})
mpris: new DBusMPRIS(appName)
};
};
6 changes: 0 additions & 6 deletions spotifywebplayer

This file was deleted.

68 changes: 31 additions & 37 deletions windows/spotify/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ module.exports = (function() {
const dbus = props.dbus;
updateMetadata = function(info){
if (dbus && info.track){
if (!dbus.mpris.metadata || (dbus.mpris.metadata && dbus.mpris.metadata['xesam:url'] !== info.track.url)) {
dbus.mpris.metadata = {
'mpris:trackid': dbus.mpris.objectPath('track/' + info.track.trackNumber),
'mpris:length': info.track.length,
'mpris:artUrl': info.track.art,
'xesam:title': info.track.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles
'xesam:album': info.track.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names
'xesam:artist': info.track.artists,
'xesam:url': info.track.url
};
}
if (dbus.mpris.volume != info.volume) dbus.mpris.volume = info.volume;
if (info.track.position && dbus.mpris.position != info.track.position) dbus.mpris.position = info.track.position;
if (dbus.mpris.playbackStatus != info.status) dbus.mpris.playbackStatus = info.status;
if (dbus.mpris.shuffle != info.shuffle) dbus.mpris.shuffle = info.shuffle;
if (dbus.mpris.repeat != info.repeat) dbus.mpris.repeat = info.repeat;
dbus.mpris.metadata = {
'mpris:trackid': dbus.mpris.objectPath('track/' + info.track.trackNumber),
'mpris:length': info.track.length,
'mpris:artUrl': info.track.art,
'xesam:title': info.track.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles
'xesam:album': info.track.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names
'xesam:artist': info.track.artists,
'xesam:url': info.track.url
};
dbus.mpris.volume = info.volume;
dbus.mpris.position = info.track.position;
dbus.mpris.playbackStatus = info.status;
dbus.mpris.shuffle = info.shuffle;
dbus.mpris.repeat = info.repeat;
}
}
class Controller extends EventEmitter {
Expand Down Expand Up @@ -114,28 +112,24 @@ module.exports = (function() {
});

if (dbus) {
console.log('setup!');
dbus.mediakeys.on('Play', () => {
console.log('RECEIVED!!!');
this.playPause();
});
dbus.mediakeys.on('Stop', this.stop);
dbus.mediakeys.on('Next', this.next);
dbus.mediakeys.on('Previous', this.previous);
dbus.mediakeys.on('Play', () => this.playPause());
dbus.mediakeys.on('Stop', () => this.stop());
dbus.mediakeys.on('Next', () => this.next());
dbus.mediakeys.on('Previous', () => this.previous());

dbus.mpris.on('Play', this.play);
dbus.mpris.on('PlayPause', this.playPause);
dbus.mpris.on('Next', this.next);
dbus.mpris.on('Previous', this.previous);
dbus.mpris.on('Stop', this.stop);
dbus.mpris.on('OpenUri', (e) => {if(e.uri.indexOf('spotify:track:') > -1){this.playTrack(e.uri)}});
dbus.mpris.on('Quit', () => { this.emit('Quit'); });
dbus.mpris.on('Raise', () => { this.emit('Raise'); });
dbus.mpris.on('Volume', (volume) => {this.setVolume(volume);});
dbus.mpris.on('Shuffle', (shuffle) => {this.setShuffle(shuffle);});
dbus.mpris.on('Loop', (loop) => {this.setLoop(loop);});
dbus.mpris.on('Seek', (mms) => {this.seek(mms.delta/1000);});
dbus.mpris.on('SetPosition', (track,pos) => {console.log('SetPosition not yet implemented')});
dbus.mpris.on('play', () => this.play());
dbus.mpris.on('playpause', () => this.playPause());
dbus.mpris.on('next', () => this.next());
dbus.mpris.on('previous', this.previous);
dbus.mpris.on('stop', this.stop);
dbus.mpris.on('openuri', (e) => {if(e.uri.indexOf('spotify:track:') > -1){this.playTrack(e.uri)}});
dbus.mpris.on('quit', () => { this.emit('Quit'); });
dbus.mpris.on('raise', () => { this.emit('Raise'); });
dbus.mpris.on('volume', (volume) => {this.setVolume(volume);});
dbus.mpris.on('shuffle', (shuffle) => {this.setShuffle(shuffle);});
dbus.mpris.on('loopStatus', (loop) => {this.setLoop(loop);});
dbus.mpris.on('seek', (mms) => {this.seek(mms.delta/1000);});
dbus.mpris.on('position', (track,pos) => {console.log('SetPosition not yet implemented')});
}
}
pause() {
Expand Down

0 comments on commit 4391d56

Please sign in to comment.