diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 13:07:50 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 13:07:50 -0500 |
| commit | f526cf641181e9cdb533a1f8a278de1fad49ca25 (patch) | |
| tree | f966ffbfa921a0f3ddb33e3e301845ed11c24db7 /wttrin.el | |
| parent | 25b760d805e98ff3c0f0f9b29f75a108fb1dce10 (diff) | |
| download | emacs-wttrin-f526cf641181e9cdb533a1f8a278de1fad49ca25.tar.gz emacs-wttrin-f526cf641181e9cdb533a1f8a278de1fad49ca25.zip | |
fix: mode-line tooltip always shows "Updated just now"
The tooltip was a static string computed at fetch time. Since every
successful fetch sets the cache timestamp to now and immediately
renders the tooltip, it was always "just now".
Extract wttrin--mode-line-tooltip as a named function that computes
age from the cache at call time. Set help-echo to this function so
Emacs invokes it on hover, producing an accurate age like
"Updated 12 minutes ago".
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -592,6 +592,21 @@ On failure with no cache, shows error placeholder." ;; No cache at all — show error placeholder (wttrin--mode-line-update-placeholder-error)))))))) +(defun wttrin--mode-line-tooltip (&optional _window _object _pos) + "Compute tooltip text from `wttrin--mode-line-cache'. +Calculates age at call time so the tooltip is always current. +Optional arguments are ignored (required by `help-echo' function protocol)." + (when wttrin--mode-line-cache + (let* ((timestamp (car wttrin--mode-line-cache)) + (weather-string (cdr wttrin--mode-line-cache)) + (age (- (float-time) timestamp)) + (stale-p (> age (* 2 wttrin-mode-line-refresh-interval))) + (age-str (wttrin--format-age age))) + (if stale-p + (format "%s\nStale: updated %s — fetch failed, will retry" + weather-string age-str) + (format "%s\nUpdated %s" weather-string age-str))))) + (defun wttrin--mode-line-update-display () "Update mode-line display from `wttrin--mode-line-cache'. Reads cached weather data, computes age, and sets the mode-line string. @@ -601,23 +616,20 @@ shows staleness info in tooltip." (let* ((timestamp (car wttrin--mode-line-cache)) (weather-string (cdr wttrin--mode-line-cache)) (age (- (float-time) timestamp)) - (stale-p (> age (* 2 wttrin-mode-line-refresh-interval))) - (age-str (wttrin--format-age age))) - (wttrin--debug-log "mode-line-display: Updating from cache, age=%s, stale=%s" - age-str stale-p) + (stale-p (> age (* 2 wttrin-mode-line-refresh-interval)))) + (wttrin--debug-log "mode-line-display: Updating from cache, stale=%s" stale-p) ;; Extract just the emoji for mode-line display - (let* ((emoji (if (string-match ":\\s-*\\(.\\)" weather-string) - (match-string 1 weather-string) - "?")) - (tooltip (if stale-p - (format "%s\nStale: updated %s — fetch failed, will retry" - weather-string age-str) - (format "%s\nUpdated %s" weather-string age-str)))) + (let ((emoji (if (string-match ":\\s-*\\(.\\)" weather-string) + (match-string 1 weather-string) + "?"))) (wttrin--debug-log "mode-line-display: Extracted emoji = %S, stale = %s" emoji stale-p) - (wttrin--set-mode-line-string - (wttrin--make-emoji-icon emoji (when stale-p "gray60")) - tooltip))))) + (setq wttrin-mode-line-string + (propertize (concat " " (wttrin--make-emoji-icon emoji (when stale-p "gray60"))) + 'help-echo #'wttrin--mode-line-tooltip + 'mouse-face 'mode-line-highlight + 'local-map wttrin--mode-line-map))))) + (force-mode-line-update t)) (defun wttrin-mode-line-click () "Handle left-click on mode-line weather widget. |
