diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-26 08:59:10 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-26 08:59:10 +0200 |
| commit | f2eec537da3de403b3201a8631e15ba6c491752d (patch) | |
| tree | 3bac911cfe791989b336b039406e23c6f06fcdb5 /assistant.py | |
| parent | be9719e61feab28612499680be9efd7411c5254f (diff) | |
| download | desktop-assistant-f2eec537da3de403b3201a8631e15ba6c491752d.tar.gz desktop-assistant-f2eec537da3de403b3201a8631e15ba6c491752d.zip | |
Pause during games too, not only in presentation mode
The status registry's effective presentation is the OR of the manual
flag and status.gaming, which the shell's game detector writes;
statusctl presentation get reads only the manual half and printed 0
with a game running. presenting() now reads both files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'assistant.py')
| -rw-r--r-- | assistant.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/assistant.py b/assistant.py index 7724b73..3bd4b20 100644 --- a/assistant.py +++ b/assistant.py @@ -119,12 +119,20 @@ def mic_on(): return out.rstrip().endswith("values=on") -def presenting(): +def presenting(d=None): # During calls the user turns on presentation mode; the button then - # belongs to the call, not to us. - r = subprocess.run([os.path.expanduser("~/bin/statusctl"), "presentation", "get"], - capture_output=True, text=True) - return r.stdout.strip() == "1" + # belongs to the call, not to us. Presentation is the OR of the manual + # flag and the game detector's (quickshell status registry: the files are + # its interface); `statusctl presentation get` reads only the manual half. + d = d or os.environ.get("XDG_RUNTIME_DIR", "/tmp") + + def flag(name): + try: + with open(os.path.join(d, f"status.{name}")) as f: + return f.read().strip() == "1" + except OSError: # a missing file means off + return False + return flag("presentation") or flag("gaming") def latin(text): @@ -500,6 +508,13 @@ def test(): assert run_tool(tools, "nope", "{}", d) == "error: no tool named nope" 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)): + with open(os.path.join(d, f"status.{name}"), "w") as f: + f.write(value) + assert presenting(d) == want, (name, value) calls = {} collect_calls(calls, [{"index": 0, "id": "c1", "type": "function", "function": {"name": "weather", "arguments": "{"}}]) |
