Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: update to mpris-service 2.0.0 (#3513)
Update the mpris-service dependency to the latest version. This update
should fix many of the outstanding issues with the GPMDP mpris
implementation.

fixes #2741
  • Loading branch information
acrisci authored and MarshallOfSound committed Mar 19, 2019
1 parent e0af8b1 commit 97ac1b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -166,7 +166,7 @@
"electron-media-service": "^0.2.2", "electron-media-service": "^0.2.2",
"ll-keyboard-hook-win": "^3.0.0", "ll-keyboard-hook-win": "^3.0.0",
"mouse-forward-back": "^1.0.1", "mouse-forward-back": "^1.0.1",
"mpris-service": "GPMDP/mpris-service" "mpris-service": "^2.0.0"
}, },
"babel": { "babel": {
"presets": [ "presets": [
Expand Down
42 changes: 26 additions & 16 deletions src/main/features/linux/mprisService.js
@@ -1,21 +1,24 @@
import { app } from 'electron'; import { app } from 'electron';
import _ from 'lodash';
import mpris from 'mpris-service'; import mpris from 'mpris-service';


function mprisService() { function mprisService() {
const mainWindow = WindowManager.getAll('main')[0]; const mainWindow = WindowManager.getAll('main')[0];
let _songInfo = {};


const player = mpris({ const player = mpris({
name: 'google-play-music-desktop-player', name: 'google_play_music_desktop_player',
identity: 'Google Play Music Desktop Player', identity: 'Google Play Music Desktop Player',
canRaise: true, canRaise: true,
supportedInterfaces: ['player'], supportedInterfaces: ['player'],
desktopEntry: 'google-play-music-desktop-player', desktopEntry: 'google-play-music-desktop-player',
}); });

player.playbackStatus = 'Stopped'; player.playbackStatus = 'Stopped';
player.canEditTracks = false; player.canEditTracks = false;


player.getPosition = function getPosition() {
return PlaybackAPI.currentTime().current * 1e3;
};

player.on('raise', () => { player.on('raise', () => {
mainWindow.setSkipTaskbar(false); mainWindow.setSkipTaskbar(false);
mainWindow.show(); mainWindow.show();
Expand Down Expand Up @@ -62,37 +65,44 @@ function mprisService() {
}); });
}); });


player.on('position', (data) => {
Emitter.sendToGooglePlayMusic('playback:seek', data.position / 1e3);
});

player.on('seek', (offset) => {
const currentTime = PlaybackAPI.currentTime().current;
const requestedTime = currentTime + (offset / 1e3);
Emitter.sendToGooglePlayMusic('playback:seek', requestedTime);
});

PlaybackAPI.on('change:track', (newSong) => { PlaybackAPI.on('change:track', (newSong) => {
player.canSeek = false; player.canSeek = true;
player.canPlay = true; player.canPlay = true;
player.canPause = true; player.canPause = true;
player.canGoPrevious = true; player.canGoPrevious = true;
player.canGoNext = true; player.canGoNext = true;
player.metadata = _songInfo = { player.metadata = {
'mpris:artUrl': newSong.albumArt.replace('=s90', '=s300'), 'mpris:artUrl': newSong.albumArt.replace('=s90', '=s300'),
'mpris:length': PlaybackAPI.currentTime().total * 1e3,
'xesam:asText': (newSong.lyrics || ''), 'xesam:asText': (newSong.lyrics || ''),
'xesam:title': newSong.title, 'xesam:title': newSong.title,
'xesam:album': newSong.album, 'xesam:album': newSong.album,
'xesam:artist': [newSong.artist], 'xesam:artist': [newSong.artist],
}; };
}); });



let lastPosition = 0;
PlaybackAPI.on('change:time', (time) => { PlaybackAPI.on('change:time', (time) => {
const newPosition = time.current * 1e3; const newPosition = time.current * 1e3;
const newTotal = time.total * 1e3;
const delta = newPosition - player.position;


if (_songInfo && _songInfo['mpris:length'] !== newTotal) { if (Math.abs(lastPosition - newPosition) > 2e6) {
player.metadata = _.extend(_songInfo, { // this event fires continuously, so only send the seeked signal when
'mpris:length': newTotal, // time jumps more than 2s.
}); player.seeked(newPosition);
} }


if (Math.abs(delta) > 2e6) { lastPosition = newPosition;
player.seeked(delta);
} else {
player.position = newPosition;
}
}); });


PlaybackAPI.on('change:state', (playbackState) => { PlaybackAPI.on('change:state', (playbackState) => {
Expand Down

0 comments on commit 97ac1b1

Please sign in to comment.