From 6f1bd002df6117bdcb49a425bdba2868e205c1fc Mon Sep 17 00:00:00 2001 From: Daniel Martins Date: Mon, 13 Jan 2025 21:59:31 -0300 Subject: [PATCH] Fix mode line auto update --- smudge-controller.el | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/smudge-controller.el b/smudge-controller.el index 7c1a3bd..44f9031 100644 --- a/smudge-controller.el +++ b/smudge-controller.el @@ -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." @@ -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."