@@ -2,6 +2,7 @@ const mpris = require("mpris-service");
22const { ipcMain } = require ( "electron" ) ;
33const registerCallback = require ( "../../providers/song-info" ) ;
44const getSongControls = require ( "../../providers/song-controls" ) ;
5+ const config = require ( "../../config" ) ;
56
67function setupMPRIS ( ) {
78 const player = mpris ( {
@@ -97,25 +98,30 @@ function registerMPRIS(win) {
9798 player . volume = value ;
9899 } ) ;
99100 player . on ( 'volume' , ( newVolume ) => {
100- // With keyboard shortcuts we can only change the volume in increments of 10, so round it.
101- const deltaVolume = Math . round ( ( newVolume - player . volume ) / 10 ) ;
102-
103- if ( deltaVolume > 0 ) {
104- for ( let i = 0 ; i < deltaVolume ; i ++ )
105- volumePlus10 ( ) ;
101+ if ( config . plugins . isEnabled ( 'precise-volume' ) ) {
102+ // With precise volume we can set the volume to the exact value.
103+ win . webContents . send ( 'setVolume' , newVolume )
106104 } else {
107- for ( let i = 0 ; i < - deltaVolume ; i ++ )
108- volumeMinus10 ( ) ;
105+ // With keyboard shortcuts we can only change the volume in increments of 10, so round it.
106+ const deltaVolume = Math . round ( ( newVolume - player . volume ) / 10 ) ;
107+
108+ if ( deltaVolume > 0 ) {
109+ for ( let i = 0 ; i < deltaVolume ; i ++ )
110+ volumePlus10 ( ) ;
111+ } else {
112+ for ( let i = 0 ; i < - deltaVolume ; i ++ )
113+ volumeMinus10 ( ) ;
114+ }
109115 }
110116 } ) ;
111117
112- registerCallback ( songInfo => {
113- if ( player ) {
114- const data = {
115- 'mpris:length' : secToMicro ( songInfo . songDuration ) ,
116- 'mpris:artUrl' : songInfo . imageSrc ,
117- 'xesam:title' : songInfo . title ,
118- 'xesam:artist' : [ songInfo . artist ] ,
118+ registerCallback ( songInfo => {
119+ if ( player ) {
120+ const data = {
121+ 'mpris:length' : secToMicro ( songInfo . songDuration ) ,
122+ 'mpris:artUrl' : songInfo . imageSrc ,
123+ 'xesam:title' : songInfo . title ,
124+ 'xesam:artist' : [ songInfo . artist ] ,
119125 'mpris:trackid' : '/'
120126 } ;
121127 if ( songInfo . album ) data [ 'xesam:album' ] = songInfo . album ;
0 commit comments