aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--dot_config/waybar/executable_mako-history.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/dot_config/waybar/executable_mako-history.py b/dot_config/waybar/executable_mako-history.py
index d12ea6f..9f4a50d 100644
--- a/dot_config/waybar/executable_mako-history.py
+++ b/dot_config/waybar/executable_mako-history.py
@@ -21,13 +21,16 @@ RECORD_RE = re.compile(r"^Notification (\d+):\s*$")
FIELD_RE = re.compile(r"^ ([A-Za-z][A-Za-z ]*?):\s*(.*)$")
-def parse_history() -> list[dict]:
+def _run_makoctl(subcmd: str) -> str:
try:
- out = subprocess.run(
- ["makoctl", "history"], capture_output=True, text=True, check=True
+ return subprocess.run(
+ ["makoctl", subcmd], capture_output=True, text=True, check=True
).stdout
except (subprocess.CalledProcessError, FileNotFoundError):
- return []
+ return ""
+
+
+def _parse_block(out: str) -> list[dict]:
notifs: list[dict] = []
cur: dict | None = None
last_field: str | None = None
@@ -47,7 +50,6 @@ def parse_history() -> list[dict]:
cur[key] = m.group(2)
last_field = key
continue
- # Body / continuation lines (mako indents with 8 spaces).
if last_field == "body" and line.startswith(" "):
cur["body"] = (cur.get("body", "") + " " + line.strip()).strip()
if cur is not None:
@@ -55,6 +57,20 @@ def parse_history() -> list[dict]:
return notifs
+def parse_history() -> list[dict]:
+ """Return visible + history notifications, deduped by id, visible first."""
+ visible = _parse_block(_run_makoctl("list"))
+ history = _parse_block(_run_makoctl("history"))
+ seen: set[int] = set()
+ out: list[dict] = []
+ for n in visible + history:
+ if n["id"] in seen:
+ continue
+ seen.add(n["id"])
+ out.append(n)
+ return out
+
+
def load_dismissed() -> set[str]:
STATE.parent.mkdir(parents=True, exist_ok=True)
STATE.touch(exist_ok=True)