chore: refactor imports and adopt new utils utilities

This commit is contained in:
sankalp committed 2026-07-14 18:45:52 +05:45
1 parent b2114f52b1
commit 6f2d0bf444
65 files changed
+221 -266

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ class ApplicationPlugin(SpotlightPlugin):
@staticmethod
def _launch_app(app: DesktopApp) -> None:
from globalmenu.launch import launch_desktop_app
from window.globalmenu.launch import launch_desktop_app
launch_desktop_app(app)
+13 -28
View File
@@ -1,10 +1,10 @@
import os
import re
import signal
import subprocess
from fabric.utils import logger
from utils.functions import format_duration, parse_timeout_string
from window.spotlight.api import SearchResult, SpotlightPlugin
_PID_FILE = os.path.join(
@@ -16,24 +16,6 @@ _INHIBIT_WHY = "Modus Caffeine"
# indefinite mode instead of relying on an in-process timer.
_INDEFINITE_SECS = 100_000_000
_DURATION_RE = re.compile(
r"^\s*(\d+)\s*(s|sec|secs|m|min|mins|h|hr|hrs|hour|hours)\s*$",
re.IGNORECASE,
)
_UNIT_SECS = {
"s": 1,
"sec": 1,
"secs": 1,
"m": 60,
"min": 60,
"mins": 60,
"h": 3600,
"hr": 3600,
"hrs": 3600,
"hour": 3600,
"hours": 3600,
}
class CaffeinePlugin(SpotlightPlugin):
id = "caffeine"
@@ -89,18 +71,21 @@ class CaffeinePlugin(SpotlightPlugin):
@staticmethod
def _parse_duration(text: str) -> int | None:
m = _DURATION_RE.match(text)
if not m:
return None
return int(m.group(1)) * _UNIT_SECS[m.group(2).lower()]
seconds = parse_timeout_string(text, in_seconds=True)
return seconds if seconds != 5 else None # 5 is the default on parse failure
@staticmethod
def _humanize(secs: int) -> str:
if secs >= 3600:
return f"{secs // 3600}h"
if secs >= 60:
return f"{secs // 60}m"
return f"{secs}s"
result = format_duration(secs)
# format_duration returns "N/A" for 0, but we want "0s"
if result == "N/A":
return "0s"
# format_duration returns "Xh Ym" or "Xm", we want shorter format
# For hours only: "1h" instead of "1h 0m"
if "h" in result and "m" in result:
hours = result.split("h")[0]
return f"{hours}h"
return result
# --- inhibition ----------------------------------------------------
+1 -1
View File
@@ -164,7 +164,7 @@ class EmojiPlugin(SpotlightPlugin):
result = self._normalize_annotations(raw) or None
if result:
logger.info(f"[Emoji] Normalized {len(result)} emojis")
logger.debug(f"[Emoji] Normalized {len(result)} emojis")
else:
logger.error("[Emoji] Normalization returned empty")
return result