diff options
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": "{"}}]) |
