Skip to content

Commit

Permalink
main: mpris: Shuffle & LoopStatus support
Browse files Browse the repository at this point in the history
  • Loading branch information
rocka committed Nov 4, 2021
1 parent 23a62e1 commit 4e8f1a7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/mpris/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const d = debug(TAG);
let msgId = 0;
// method/setter ipc
// DBus ------------> Main --> Renderer
const DBusEvents = ['raise', 'quit', 'next', 'prev', 'play', 'pause', 'stop', 'seek', 'volume', 'position'];
const DBusEvents = ['raise', 'quit', 'next', 'prev', 'play', 'pause', 'stop', 'seek', 'volume', 'position', 'shuffle', 'loop'];

ipcMain.on(TAG, (_, /** @type {string} */ type, ...args) => {
d('↓ %s', type);
Expand Down
57 changes: 41 additions & 16 deletions src/main/mpris/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const i = {

let serviceName = 'ElectronNCM';
if (process.env.NODE_ENV === 'development') {
serviceName += '.debug';
serviceName += '.dev';
}

class MediaPlayer2 extends Interface {
Expand Down Expand Up @@ -170,25 +170,44 @@ class MediaPlayer2Player extends Interface {
Track: 'Track',
Playlist: 'Playlist'
}
};

@property({ signature: 's', access: ACCESS_READWRITE })
get LoopStatus() {
return this._LoopStatus.value;
}

set LoopStatus(value) {
this.setLoopStatus(value);
this.emitter.emit('dbus:loop', value);
}

// @property({ signature: 's', access: ACCESS_READWRITE })
// get LoopStatus() {
// return this._LoopStatus.value;
// }
setLoopStatus(value) {
this._LoopStatus.value = value;
Interface.emitPropertiesChanged(this, {
LoopStatus: this._LoopStatus.value
});
}

// set LoopStatus(value) {
// this._LoopStatus.value = value;
// Interface.emitPropertiesChanged(this, {
// Metadata: this._LoopStatus.value
// });
// }
_Shuffle = false;

// @property({ signature: 'b', access: ACCESS_READWRITE })
// Shuffle = false;
@property({ signature: 'b', access: ACCESS_READWRITE })
get Shuffle() { return this._Shuffle; }

set Shuffle(value) {
this.setShuffle(value);
this.emitter.emit('dbus:shuffle', value);
}

setShuffle(value) {
this._Shuffle = value;
Interface.emitPropertiesChanged(this, {
Shuffle: this._Shuffle
});
}

_Volume = 1.0;
_ThrottledVloume = throttle(value => this.emitter.emit('dbus:volume', Math.trunc(value * 100)), 100)
_ThrottledVloume = throttle(value => this.emitter.emit('dbus:volume', Math.trunc(value * 100)), 100);

@property({ signature: 'd', access: ACCESS_READWRITE })
get Volume() { return this._Volume; }
Expand Down Expand Up @@ -277,6 +296,12 @@ class MediaPlayer2Player extends Interface {
this.timer.offset(offset * 1e3);
}

@method({ inSignature: 's' })
OpenUri(Uri) {
d('method: OpenUri, %s', Uri);
// TODO: fit something here
}

@method({ inSignature: 'ox' })
SetPosition(TrackId, Position) {
d('method: SetPosition %s %d', TrackId, Position);
Expand Down Expand Up @@ -311,8 +336,8 @@ class MPRISEmitter extends EventEmitter {
this.on('play', () => this.mp2Player.setPlaybackStatus(this.mp2Player._PlaybackStatus.types.Playing));
this.on('pause', () => this.mp2Player.setPlaybackStatus(this.mp2Player._PlaybackStatus.types.Paused));
this.on('stop', () => this.mp2Player.setPlaybackStatus(this.mp2Player._PlaybackStatus.types.Stopped));
this.on('loopStatus', val => this.mp2Player.LoopStatus = val);
this.on('shuffle', shuf => this.mp2Player.Shuffle = shuf);
this.on('loop', loop => this.mp2Player.setLoopStatus(loop));
this.on('shuffle', shuffle => this.mp2Player.setShuffle(shuffle));
this.on('metadata', meta => this.mp2Player.setMetadata(meta));
this.on('volume', vol => this.mp2Player.setVolume(vol));
this.on('seeked', seconds => this.mp2Player.Seeked(seconds));
Expand Down

0 comments on commit 4e8f1a7

Please sign in to comment.