Skip to content
Permalink
Browse files

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 97ac1b193a0a3d177d17c1ff556c18dc32aa2e14
Showing with 27 additions and 17 deletions.
  1. +1 −1 package.json
  2. +26 −16 src/main/features/linux/mprisService.js
@@ -166,7 +166,7 @@
"electron-media-service": "^0.2.2",
"ll-keyboard-hook-win": "^3.0.0",
"mouse-forward-back": "^1.0.1",
"mpris-service": "GPMDP/mpris-service"
"mpris-service": "^2.0.0"
},
"babel": {
"presets": [
@@ -1,21 +1,24 @@
import { app } from 'electron';
import _ from 'lodash';
import mpris from 'mpris-service';

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

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

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

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

player.on('raise', () => {
mainWindow.setSkipTaskbar(false);
mainWindow.show();
@@ -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) => {
player.canSeek = false;
player.canSeek = true;
player.canPlay = true;
player.canPause = true;
player.canGoPrevious = true;
player.canGoNext = true;
player.metadata = _songInfo = {
player.metadata = {
'mpris:artUrl': newSong.albumArt.replace('=s90', '=s300'),
'mpris:length': PlaybackAPI.currentTime().total * 1e3,
'xesam:asText': (newSong.lyrics || ''),
'xesam:title': newSong.title,
'xesam:album': newSong.album,
'xesam:artist': [newSong.artist],
};
});


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

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

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

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

0 comments on commit 97ac1b1

Please sign in to comment.
You can’t perform that action at this time.