Skip to content

Commit

Permalink
✨ add mpris check if is Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed May 29, 2020
1 parent 0c4752e commit c924b3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (settingsProvider.get('settings-discord-rich-presence')) {
discordRPC.start()
}

//mprisProvider.start()
mprisProvider.start()

let renderer_for_status_bar = null
global.sharedObj = { title: 'N/A', paused: true }
Expand Down Expand Up @@ -291,7 +291,7 @@ function createWindow() {
view.webContents.on('media-started-playing', function() {
if (!infoPlayerProvider.hasInitialized()) {
infoPlayerProvider.init(view)
//mprisProvider.setRealPlayer(infoPlayerProvider) //this lets us keep track of the current time in playback.
mprisProvider.setRealPlayer(infoPlayerProvider) //this lets us keep track of the current time in playback.
}

if (isMac()) {
Expand Down Expand Up @@ -337,7 +337,7 @@ function createWindow() {

discordRPC.setActivity(getAll())
rainmeterNowPlaying.setActivity(getAll())
//mprisProvider.setActivity(getAll())
mprisProvider.setActivity(getAll())

mediaControl.createThumbar(mainWindow, infoPlayerProvider.getAllInfo())

Expand Down
60 changes: 36 additions & 24 deletions providers/mprisProvider.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
const { ipcMain } = require('electron')
const mpris = require('mpris-service')
const { isLinux } = require('../utils/systemInfo')

class Mpris {
constructor() {
this._isInitialized = false
this.player = undefined
this.realPlayer = undefined //we'll need the infoPlayer later to be better able to track the time.
this._realPlayer = undefined //we'll need the infoPlayer later to be better able to track the time.
}

start() {
this.player = new mpris({
name: 'youtubemusic',
identity: 'Youtube Music',
supportedUriSchemes: ['file'],
supportedMimeTypes: ['audio/mpeg', 'application/ogg'],
supportedInterfaces: ['player'],
})
if (isLinux()) {
this.player = new mpris({
name: 'youtubemusic',
identity: 'Youtube Music',
supportedUriSchemes: ['file'],
supportedMimeTypes: ['audio/mpeg', 'application/ogg'],
supportedInterfaces: ['player'],
})

this._setInitialEvents()

this.setInitialEvents()
this._isInitialized = true
}
}

setRealPlayer(infoPlayer) {
this.realPlayer = infoPlayer
//Overriding this method makes it a lot easier to be able to controll the playback position.
this.player.getPosition = () =>
this.realPlayer.getPlayerInfo().seekbarCurrentPosition * 1000 * 1000
if (this.player) {
this._realPlayer = infoPlayer
//Overriding this method makes it a lot easier to be able to controll the playback position.
this.player.getPosition = () =>
this._realPlayer.getPlayerInfo().seekbarCurrentPosition *
1000 *
1000
}
}

setActivity(info) {
this.player.metadata = {
'mpris:trackid': this.player.objectPath('track/0'),
'mpris:length': info.track.duration * 1000 * 1000, // In microseconds
'mpris:artUrl': info.track.cover,
'xesam:title': info.track.title,
'xesam:album': info.track.album,
'xesam:artist': [info.track.author],
if (this._isInitialized) {
this.player.metadata = {
'mpris:trackid': this.player.objectPath('track/0'),
'mpris:length': info.track.duration * 1000 * 1000, // In microseconds
'mpris:artUrl': info.track.cover,
'xesam:title': info.track.title,
'xesam:album': info.track.album,
'xesam:artist': [info.track.author],
}
this.player.playbackStatus = info.player.isPaused
? mpris.PLAYBACK_STATUS_PAUSED
: mpris.PLAYBACK_STATUS_PLAYING
}
this.player.playbackStatus = info.player.isPaused
? mpris.PLAYBACK_STATUS_PAUSED
: mpris.PLAYBACK_STATUS_PLAYING
}

setInitialEvents() {
_setInitialEvents() {
const events = {
quit: () => process.exit(0),
previous: 'media-track-previous',
Expand Down

0 comments on commit c924b3a

Please sign in to comment.