diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 13:26:10 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 13:26:10 -0500 |
| commit | de99a2930bbe65d7c2ea04656caa18823068c182 (patch) | |
| tree | 14c2300f48fe4ef0a29b0d3327e45a691e5672bb | |
| parent | 752e2f825b1ee3eb513e27f2c03bcaef30eec767 (diff) | |
| download | emacs-wttrin-de99a2930bbe65d7c2ea04656caa18823068c182.tar.gz emacs-wttrin-de99a2930bbe65d7c2ea04656caa18823068c182.zip | |
fix: emoji dimming can disagree with tooltip staleness
The emoji face (dimmed/normal) was frozen at the last update-display
call, but the tooltip computes staleness dynamically. Between
refreshes, data could cross the stale threshold — tooltip says "Stale"
while the emoji is still normal.
Track the rendered staleness state. When the tooltip detects a
transition, trigger a re-render so the emoji dimming matches.
| -rw-r--r-- | tests/test-wttrin--mode-line-update-display.el | 26 | ||||
| -rw-r--r-- | wttrin.el | 10 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/test-wttrin--mode-line-update-display.el b/tests/test-wttrin--mode-line-update-display.el index 81fbded..0635b5f 100644 --- a/tests/test-wttrin--mode-line-update-display.el +++ b/tests/test-wttrin--mode-line-update-display.el @@ -210,6 +210,32 @@ (should-not wttrin-mode-line-string)) (test-wttrin--mode-line-update-display-teardown))) +(ert-deftest test-wttrin--mode-line-update-display-stale-emoji-dims-on-hover-transition () + "When data crosses the stale threshold between refreshes, hovering should +trigger an emoji re-render so dimming matches the tooltip's staleness state." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-mode-line-refresh-interval 900) + (wttrin-mode-line-emoji-font nil)) + ;; Initial render: data is fresh (age=200, threshold=1800) + (cl-letf (((symbol-function 'float-time) (lambda () 1200.0))) + (setq wttrin--mode-line-cache (cons 1000.0 "Paris: X +61°F Clear")) + (wttrin--mode-line-update-display) + ;; Emoji should NOT be dimmed + (let ((face (get-text-property 1 'face wttrin-mode-line-string))) + (should-not (and face (equal (plist-get face :foreground) "gray60"))))) + + ;; Time passes: data is now stale (age=2001, threshold=1800) + ;; Invoke the tooltip (simulating a hover) — this should trigger a re-render + (cl-letf (((symbol-function 'float-time) (lambda () 3001.0))) + (let ((help-echo-fn (get-text-property 0 'help-echo wttrin-mode-line-string))) + (funcall help-echo-fn nil nil nil)) + ;; After hover detected staleness transition, emoji should now be dimmed + (let ((face (get-text-property 1 'face wttrin-mode-line-string))) + (should face) + (should (equal (plist-get face :foreground) "gray60"))))) + (test-wttrin--mode-line-update-display-teardown))) + ;;; -------------------------------------------------------------------------- ;;; wttrin--mode-line-fetch-weather ;;; -------------------------------------------------------------------------- @@ -200,6 +200,9 @@ Set this to t BEFORE loading wttrin, typically in your init file: When non-nil, car is the `float-time' when data was fetched, and cdr is the weather string from the API.") +(defvar wttrin--mode-line-rendered-stale nil + "Whether the mode-line emoji is currently rendered as stale (dimmed).") + (defvar wttrin--mode-line-map (let ((map (make-sparse-keymap))) (define-key map [mode-line mouse-1] 'wttrin-mode-line-click) @@ -594,6 +597,8 @@ On failure with no cache, shows error placeholder." (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. +If staleness has changed since the last render, triggers a re-render +so the emoji dimming matches. Optional arguments are ignored (required by `help-echo' function protocol)." (when wttrin--mode-line-cache (let* ((timestamp (car wttrin--mode-line-cache)) @@ -601,6 +606,9 @@ Optional arguments are ignored (required by `help-echo' function protocol)." (age (- (float-time) timestamp)) (stale-p (> age (* 2 wttrin-mode-line-refresh-interval))) (age-str (wttrin--format-age age))) + ;; Re-render emoji if staleness state has changed + (unless (eq stale-p wttrin--mode-line-rendered-stale) + (wttrin--mode-line-update-display)) (if stale-p (format "%s\nStale: updated %s — fetch failed, will retry" weather-string age-str) @@ -623,6 +631,7 @@ shows staleness info in tooltip." "?"))) (wttrin--debug-log "mode-line-display: Extracted emoji = %S, stale = %s" emoji stale-p) + (setq wttrin--mode-line-rendered-stale stale-p) (setq wttrin-mode-line-string (propertize (concat " " (wttrin--make-emoji-icon emoji (when stale-p "gray60"))) 'help-echo #'wttrin--mode-line-tooltip @@ -708,6 +717,7 @@ opens the weather buffer." (setq wttrin--buffer-refresh-timer nil)) (setq wttrin-mode-line-string nil) (setq wttrin--mode-line-cache nil) + (setq wttrin--mode-line-rendered-stale nil) (force-mode-line-update t)) ;;;###autoload |
