From 19e103fea2e55a3e3bc3a777b4c618e644b57760 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 28 Jun 2026 03:56:24 -0400 Subject: fix: stop the mode-line cleanly when disabled before startup fires The delayed initial fetch was scheduled with run-at-time but the one-shot timer was discarded, and when the mode is enabled before after-init the start is queued on after-init-hook. Disabling the mode before either fired could still start timers, hit the network, or mutate mode-line state after the user turned it off. Stop now cancels the stored startup timer and removes the after-init hook, and the startup callback no-ops when the mode is off. --- tests/test-wttrin--mode-line-start.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/test-wttrin--mode-line-start.el') diff --git a/tests/test-wttrin--mode-line-start.el b/tests/test-wttrin--mode-line-start.el index 1b86689..21cdb24 100644 --- a/tests/test-wttrin--mode-line-start.el +++ b/tests/test-wttrin--mode-line-start.el @@ -21,7 +21,8 @@ (setq wttrin-mode-line-string nil) (setq wttrin--mode-line-cache nil) (setq wttrin--mode-line-timer nil) - (setq wttrin--buffer-refresh-timer nil)) + (setq wttrin--buffer-refresh-timer nil) + (setq wttrin--mode-line-startup-timer nil)) (defun test-wttrin--mode-line-start-teardown () "Teardown for mode-line-start tests." @@ -30,10 +31,13 @@ (cancel-timer wttrin--mode-line-timer)) (when (timerp wttrin--buffer-refresh-timer) (cancel-timer wttrin--buffer-refresh-timer)) + (when (timerp wttrin--mode-line-startup-timer) + (cancel-timer wttrin--mode-line-startup-timer)) (setq wttrin-mode-line-string nil) (setq wttrin--mode-line-cache nil) (setq wttrin--mode-line-timer nil) - (setq wttrin--buffer-refresh-timer nil)) + (setq wttrin--buffer-refresh-timer nil) + (setq wttrin--mode-line-startup-timer nil)) ;;; Normal Cases @@ -70,8 +74,10 @@ (null (plist-get call :repeat)))) scheduled-calls))) (should initial-fetch) + ;; The delayed fetch goes through the enabled-guard wrapper so a + ;; disable before it fires is a no-op. (should (eq (plist-get initial-fetch :func) - #'wttrin--mode-line-fetch-weather))))) + #'wttrin--mode-line-fetch-weather-if-enabled))))) (test-wttrin--mode-line-start-teardown))) (ert-deftest test-wttrin--mode-line-start-normal-creates-repeating-mode-line-timer () -- cgit v1.2.3