Skip to content

Commit

Permalink
Fix mode line auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfm committed Jan 14, 2025
1 parent b768a65 commit 6f1bd00
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions smudge-controller.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ Apply SUFFIX to smudge-controller-prefixed functions, applying ARGS."
:array-type 'list
:object-type 'hash-table)
(error nil))))
(when json
(setq player-status (replace-regexp-in-string "%a" (truncate-string-to-width (gethash "artist" json) smudge-player-status-truncate-length 0 nil "...") player-status)
player-status (replace-regexp-in-string "%t" (truncate-string-to-width (gethash "name" json) smudge-player-status-truncate-length 0 nil "...") player-status)
player-status (replace-regexp-in-string "%n" (number-to-string (gethash "track_number" json)) player-status)
player-status (replace-regexp-in-string "%l" (format-seconds duration-format (/ (gethash "duration" json) 1000)) player-status)
player-status (replace-regexp-in-string "%s" (smudge-controller-player-status-shuffling-indicator (gethash "player_shuffling" json)) player-status)
player-status (replace-regexp-in-string "%r" (smudge-controller-player-status-repeating-indicator (gethash "player_repeating" json)) player-status)
player-status (replace-regexp-in-string "%p" (smudge-controller-player-status-playing-indicator (gethash "player_state" json)) player-status))
(smudge-controller-update-player-status player-status)
(setq smudge-controller-player-metadata json))))
(if json
(progn
(setq player-status (replace-regexp-in-string "%a" (truncate-string-to-width (gethash "artist" json) smudge-player-status-truncate-length 0 nil "...") player-status)
player-status (replace-regexp-in-string "%t" (truncate-string-to-width (gethash "name" json) smudge-player-status-truncate-length 0 nil "...") player-status)
player-status (replace-regexp-in-string "%n" (number-to-string (gethash "track_number" json)) player-status)
player-status (replace-regexp-in-string "%l" (format-seconds duration-format (/ (gethash "duration" json) 1000)) player-status)
player-status (replace-regexp-in-string "%s" (smudge-controller-player-status-shuffling-indicator (gethash "player_shuffling" json)) player-status)
player-status (replace-regexp-in-string "%r" (smudge-controller-player-status-repeating-indicator (gethash "player_repeating" json)) player-status)
player-status (replace-regexp-in-string "%p" (smudge-controller-player-status-playing-indicator (gethash "player_state" json)) player-status))
(smudge-controller-update-player-status player-status)
(setq smudge-controller-player-metadata json))
(smudge-controller-update-player-status ""))))

(defun smudge-controller-update-player-status (str)
"Set the given STR to the player status, prefixed with the mode identifier."
Expand Down Expand Up @@ -198,7 +200,7 @@ This corresponds to the current REPEATING state."
"Start the timer that will update the mode line with Spotify player status."
(when (and (not (smudge-controller-timerp)) (> smudge-player-status-refresh-interval 0))
(setq smudge-controller-timer
(run-at-time t smudge-player-status-refresh-interval #'smudge-controller-player-status))))
(run-at-time t smudge-player-status-refresh-interval 'smudge-controller-player-status))))

(defun smudge-controller-stop-player-status-timer ()
"Stop the timer that is updating the mode line."
Expand Down

0 comments on commit 6f1bd00

Please sign in to comment.