@@ -72,23 +72,17 @@ let buttonNext,
7272 labelSeperatorStart ,
7373 labelSeperatorEnd ;
7474
75- // Constants
76-
77- const playerIcons = {
78- default : "audio-x-generic-symbolic" ,
79- chromium : "chromium" ,
80- firefox : "firefox" ,
81- rhythmbox : "rhythmbox" ,
82- spotify : "spotify" ,
83- vlc : "vlc" ,
84- } ;
75+ // Other variables
76+
77+ const playerIconExceptions = [ "chromium" ] ;
8578
8679const positions = {
8780 left : "_leftBox" ,
8881 center : "_centerBox" ,
8982 right : "_rightBox" ,
9083} ;
9184
85+ // playback actions
9286const playbackActions = {
9387 none : ( ) => { } ,
9488 toggle_play : ( ) => {
@@ -117,15 +111,9 @@ const playbackActions = {
117111
118112// Performs corresponding mouse action
119113const _mouseAction = ( event ) => {
120- // log("came here");
121- // log(event.pseudo_class);
122114 if ( event . pseudo_class && event . pseudo_class . includes ( "active" ) ) {
123- // log(mouseActionsLeftClick);
124- // log("Came here but upper case");
125115 playbackActions [ mouseActionsLeftClick ] ( ) ;
126116 } else {
127- // log("Doesn't include");
128- // log(mouseActionsRightClick);
129117 playbackActions [ mouseActionsRightClick ] ( ) ;
130118 }
131119} ;
@@ -160,8 +148,6 @@ const updatePlayerIconEffects = () => {
160148// Housekeeping methods
161149
162150const addContent = ( ) => {
163- // let currentIndex;
164- // log(`Adding to ${extensionPosition} box`);
165151 if ( contentRemoved ) {
166152 let currentIndex = 0 ;
167153 elementOrder . forEach ( ( element ) => {
@@ -173,8 +159,8 @@ const addContent = () => {
173159 ) ;
174160 currentIndex ++ ;
175161 }
176- // Add opening seperator
177162 if ( element === "title" && ! hideTrackName ) {
163+ // Add opening seperator
178164 if ( ! hideSeperators ) {
179165 Main . panel [
180166 positions [ extensionPosition ]
@@ -184,8 +170,8 @@ const addContent = () => {
184170 ) ;
185171 currentIndex ++ ;
186172 }
187- // Add track title
188173
174+ // Add track title
189175 Main . panel [ positions [ extensionPosition ] ] . insert_child_at_index (
190176 buttonLabel ,
191177 extensionIndex + currentIndex
@@ -203,7 +189,8 @@ const addContent = () => {
203189 currentIndex ++ ;
204190 }
205191 }
206- // Add controls
192+
193+ // Add player control icons
207194 if ( element === "controls" && ! hideControls ) {
208195 Main . panel [ positions [ extensionPosition ] ] . insert_child_at_index (
209196 buttonPrev ,
@@ -228,9 +215,8 @@ const addContent = () => {
228215} ;
229216
230217const removeContent = ( ) => {
231- // extensionPosition, extensionPosition Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah
232- // log(`Removing from ${extensionPosition} box`);
233-
218+ // Remove content if not already removed.
219+ // NOTE: Checking before removing is essential else it will spam the journalctl with warnings
234220 if ( ! contentRemoved ) {
235221 Main . panel [ positions [ extensionPosition ] ] . remove_actor ( buttonNext ) ;
236222 Main . panel [ positions [ extensionPosition ] ] . remove_actor ( buttonToggle ) ;
@@ -250,8 +236,8 @@ const removeContent = () => {
250236// Utility methods
251237
252238const updateMetadata = async ( ) => {
253- // log("Updating metadata");
254239 try {
240+ // Retrieve player list
255241 playersList = await getPlayers ( ) ;
256242 if ( playersList . length > 0 ) {
257243 let playerStateMap = [ ] ;
@@ -264,7 +250,14 @@ const updateMetadata = async () => {
264250 [ _playerState , [ _title , _artist , _url ] ] = await Promise . all (
265251 [ _playerStatePromise , _metadataPromise ]
266252 ) ;
267- if ( _title || _url ) {
253+
254+ // If the title or the url is valid add the player
255+ if (
256+ _title ||
257+ ( _url &&
258+ _url !==
259+ "/org/mpris/MediaPlayer2/TrackList/NoTrack" )
260+ ) {
268261 playerStateMap . push ( [ player , _playerState ] ) ;
269262 playerDataMap [ player ] = {
270263 _title : _title || _url ,
@@ -275,13 +268,15 @@ const updateMetadata = async () => {
275268 }
276269 }
277270
271+ // Get the list of players that are currently playing
278272 let playingPlayers = playerStateMap . filter ( ( [ player , state ] ) => {
279273 if ( state === "Playing" ) {
280274 return true ;
281275 }
282276 return false ;
283277 } ) ;
284278
279+ // If any of the player are playing set the current player else get the first paused player
285280 if ( playingPlayers . length > 0 ) {
286281 if ( contentRemoved ) {
287282 addContent ( ) ;
@@ -320,48 +315,39 @@ const updateMetadata = async () => {
320315} ;
321316
322317const updateData = ( player , _playerState , _title , _artist ) => {
323- // log("Updating data");
324318 let currentMetadata = `${ _title } ${ _artist ? " - " + _artist : "" } ` ;
325- let splittedPlayer = player . split ( "." ) ;
326319 if ( lastPlayer !== player ) {
327- // log("Updating player");
328320 currentPlayer = player ;
329321 lastPlayer = player ;
330- playerIcon = playerIcons [ "default" ] ;
331- for ( [ key , value ] of Object . entries ( playerIcons ) ) {
332- if ( splittedPlayer . includes ( key ) ) {
333- playerIcon = playerIcons [ key ] ;
334- break ;
322+ playerIcon = null ;
323+ playerIconExceptions . forEach ( ( exception ) => {
324+ if ( player . includes ( exception ) ) {
325+ playerIcon = exception ;
335326 }
327+ } ) ;
328+ if ( ! playerIcon ) {
329+ let splittedPlayer = player . split ( "." ) ;
330+ playerIcon = splittedPlayer [ splittedPlayer . length - 1 ] ;
331+ log ( playerIcon ) ;
336332 }
337333 lastPlayerChanged = true ;
338334 }
339335 if ( lastState !== _playerState ) {
340- // log("Updating player state");
341336 playerState = _playerState ;
342337 lastState = _playerState ;
343338 lastStateChanged = true ;
344339 }
345340 if ( currentMetadata !== lastMetadata ) {
346- // log("Updating player metadata");
347341 lastMetadata = currentMetadata ;
348342 displayText = currentMetadata ;
349343 lastMetadataChanged = true ;
350344 }
351345 if ( lastMetadata . length > maxDisplayLength && maxDisplayLength !== 0 ) {
352346 if ( mouseHovered && showAllOnHover ) {
353- // log("Mouse hovered...");
354347 displayText = lastMetadata ;
355- // let diff = lastMetadata.length - maxDisplayLength;
356- // displayText =
357- // "..." +
358- // lastMetadata.substr(lastMetadata.length - diff - 3) +
359- // " ".repeat(maxDisplayLength - diff);
360- // log(displayText.length);
361348 } else {
362349 displayText =
363350 lastMetadata . substring ( 0 , maxDisplayLength - 3 ) + "..." ;
364- // log(displayText.length);
365351 }
366352 } else {
367353 displayText = lastMetadata ;
@@ -392,7 +378,6 @@ const startMainLoop = () => {
392378 }
393379 mainLoop = Mainloop . timeout_add ( updateDelay , ( ) => {
394380 ( async ( ) => {
395- // startTime = Date.now();
396381 await updateMetadata ( ) ;
397382 updateContent ( ) ;
398383 } ) ( ) ;
@@ -568,7 +553,7 @@ const enable = () => {
568553 style : "padding: 0px;" ,
569554 } ) ;
570555 iconPlayer = new St . Icon ( {
571- icon_name : playerIcons . default ,
556+ fallback_icon_name : "audio-x-generic-symbolic" ,
572557 icon_size : 16 ,
573558 } ) ;
574559
0 commit comments