Skip to content

Commit

Permalink
lots of general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Mar 11, 2024
1 parent 66fd761 commit 5f6d9c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
20 changes: 18 additions & 2 deletions core/screenreader_ipc/ipc_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions nvda/nvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ 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"""
if actions.user.is_nvda_running():
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):
Expand Down
2 changes: 1 addition & 1 deletion utils/access-focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 5f6d9c8

Please sign in to comment.