From 36158ffbbb4cf034c3c90789fb69f098ec9f6433 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 28 Jul 2026 21:13:54 +0545 Subject: [PATCH] fix(spotlight): return empty for unrelated caffeine queries Add had_prefix flag so caffeine.search() returns [] for queries without 'caffeine' or 'caff' prefix instead of always showing help. Add debug logging. --- src/window/spotlight/plugins/caffeine.py | 31 +++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/window/spotlight/plugins/caffeine.py b/src/window/spotlight/plugins/caffeine.py index 4e78cfc..5b7b908 100644 --- a/src/window/spotlight/plugins/caffeine.py +++ b/src/window/spotlight/plugins/caffeine.py @@ -212,29 +212,38 @@ class CaffeinePlugin(SpotlightPlugin): def search(self, query: str, token) -> list[SearchResult]: q = query.strip().lower() + had_prefix = False for kw in ("caffeine ", "caff "): if q.startswith(kw): q = q[len(kw) :].strip() + had_prefix = True break active = self.is_active() + logger.info( + f"[Caffeine] search query={query!r} q={q!r} had_prefix={had_prefix} active={active}" + ) if not q or q in ("caffeine", "caff"): + logger.info("[Caffeine] returning menu (keyword match)") return self._menu(active) if q == "off": + logger.info("[Caffeine] returning off") return [ self._mk( "off", "Disable Caffeine", "Allow idle and sleep again", active ) ] if q == "on": + logger.info("[Caffeine] returning on") return [ self._mk("on", "Enable Caffeine", "Stay awake until turned off", active) ] secs = self._parse_duration(q) if secs is not None: + logger.info(f"[Caffeine] returning duration secs={secs}") return [ self._mk( q, @@ -244,15 +253,19 @@ class CaffeinePlugin(SpotlightPlugin): ) ] - return [ - self._result( - "caffeine_help", - "Caffeine", - "Usage: caffeine on | off |