aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-26 09:36:46 +0200
committerDanilo M. <danix@danix.xyz>2026-09-26 09:36:46 +0200
commitca033a33c79a98ede71c3147133c5071f37c2c67 (patch)
tree3f8a51def87ff689ee3ee4ec20e8b039b00acae6
parentf2b96f606ca671f0cc77ebfe205e38a97794f074 (diff)
downloaddesktop-assistant-ca033a33c79a98ede71c3147133c5071f37c2c67.tar.gz
desktop-assistant-ca033a33c79a98ede71c3147133c5071f37c2c67.zip
Notify when a press is ignored in presentation or gaming mode
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--assistant.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/assistant.py b/assistant.py
index 7f8fd1d..7052d69 100644
--- a/assistant.py
+++ b/assistant.py
@@ -138,7 +138,24 @@ def presenting(d=None):
return f.read().strip() == "1"
except OSError: # a missing file means off
return False
- return flag("presentation") or flag("gaming")
+ # Why the press is ignored, for the notification; "" when it is not.
+ return "gaming" if flag("gaming") else "presentation" if flag("presentation") else ""
+
+
+notify_id = ""
+
+
+def notify_ignored(reason):
+ # Normal urgency: DND (on during presentation mode) holds it back from
+ # popping over a call or a game, and it waits in the notification list.
+ # Each press replaces the last (-r), so one game makes one entry.
+ global notify_id
+ cmd = ["notify-send", "-a", "desktop-assistant", "-u", "normal", "-p"]
+ if notify_id:
+ cmd += ["-r", notify_id]
+ cmd += ["Voice assistant paused", f"The button press was ignored: {reason} mode is on."]
+ r = subprocess.run(cmd, capture_output=True, text=True)
+ notify_id = r.stdout.strip() or notify_id
def latin(text):
@@ -474,8 +491,10 @@ def main():
if on == prev:
continue
prev = on
- if on and presenting():
- log("presentation mode: ignored")
+ reason = presenting() if on else ""
+ if reason:
+ log(f"{reason} mode: ignored")
+ notify_ignored(reason)
elif on:
# Barge-in: a press silences the reply now and makes it stale.
turn += 1
@@ -545,9 +564,9 @@ def test():
assert run_tool(tools, "echo", "{bad", d) == "error: arguments are not valid JSON"
assert run_tool(tools, "echo", "[1]", d) == "error: arguments are not valid JSON"
with tempfile.TemporaryDirectory() as d:
- assert not presenting(d)
- for name, value, want in (("gaming", "1", True), ("gaming", "0", False),
- ("presentation", "1\n", True)):
+ assert presenting(d) == ""
+ for name, value, want in (("gaming", "1", "gaming"), ("gaming", "0", ""),
+ ("presentation", "1\n", "presentation")):
with open(os.path.join(d, f"status.{name}"), "w") as f:
f.write(value)
assert presenting(d) == want, (name, value)