diff --git a/core/screenreader_ipc/ipc_client.py b/core/screenreader_ipc/ipc_client.py index 666c08d..420f816 100644 --- a/core/screenreader_ipc/ipc_client.py +++ b/core/screenreader_ipc/ipc_client.py @@ -1,4 +1,4 @@ -from talon import Module, Context, actions, settings +from talon import Module, Context, actions, settings, cron import os import ipaddress import json @@ -147,7 +147,23 @@ def send_ipc_commands( if not actions.user.is_nvda_running(): return - ip, port, valid_commands = actions.user.addon_server_endpoint() + try: + ip, port, valid_commands = actions.user.addon_server_endpoint() + except FileNotFoundError: + # If we just shut the server down via a talon command + # we need to check again after a delay once the controller + # client is updated + def check_if_shutdown(): + if not actions.user.is_nvda_running(): + # Ignore, we expect the server to be shut down + # and the file to be gone + return + else: + raise FileNotFoundError( + "NVDA is running but the server spec file is missing" + ) + + cron.after("2s", check_if_shutdown) for command in commands: if command not in valid_commands: diff --git a/nvda/nvda.py b/nvda/nvda.py index 90c9020..4098e85 100644 --- a/nvda/nvda.py +++ b/nvda/nvda.py @@ -40,8 +40,9 @@ def toggle_nvda(): elif actions.user.is_nvda_running(): actions.user.with_nvda_mod_press("q") actions.user.tts("Turning NVDA off") - time.sleep(1) - actions.key("enter") + # We need this delay so the post-phrase callback + # can be set even if nvda is turned off + cron.after("2s", lambda: actions.key("enter")) def restart_nvda(): """Restarts NVDA""" @@ -49,8 +50,9 @@ def restart_nvda(): actions.user.with_nvda_mod_press("q") time.sleep(0.5) actions.key("down") - time.sleep(0.5) - actions.key("enter") + # We need this delay so the post-phrase callback + # can be set even if nvda is turned off + cron.after("2s", lambda: actions.key("enter")) actions.user.tts("Restarting NVDA") def with_nvda_mod_press(key: str): diff --git a/utils/access-focus.py b/utils/access-focus.py index e327e0f..b93f7ea 100644 --- a/utils/access-focus.py +++ b/utils/access-focus.py @@ -69,7 +69,7 @@ def focus_element_by_name(name: str, permissive: bool = True): try: # https://learn.microsoft.com/en-us/windows/win32/winauto/selflag # SELFLAG_TAKESELECTION = 2 - # Ideally we would use .select() but the API doesn't work + # We can also use .select() element.legacyiaccessible_pattern.do_default_action() except Exception as f: actions.user.tts(f"Failed to focus {name}")