Skip to content

Commit

Permalink
change ipc api
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Feb 15, 2024
1 parent 09972d2 commit 5805add
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
19 changes: 0 additions & 19 deletions core/addon_communication/ipc_schema.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ class Actions:
def addon_server_endpoint() -> Tuple[str, str, str]:
"""Returns the address, port, and valid commands for the addon server"""

def send_ipc_commands(commands: list[IPC_COMMAND] | IPC_COMMAND):
def send_ipc_commands(commands: list[IPC_COMMAND]):
"""Sends a command or commands to the screenreader"""

def send_ipc_command(command: IPC_COMMAND):
"""
Sends a single command to the screenreader.
This is its own function since old versions of talon
don't support union type hints and having a separate
function is a workaround a clearer API than passing in a list
for a single command
"""

NVDAContext = Context()
NVDAContext.matches = r"""
tag: user.nvda_running
Expand Down Expand Up @@ -44,14 +53,10 @@ def addon_server_endpoint() -> Tuple[str, str, str]:

return address, port, valid_commands


def send_ipc_commands(commands: list[IPC_COMMAND] | IPC_COMMAND):
def send_ipc_commands(commands: list[IPC_COMMAND]):
"""Sends a list of commands or a single command string to the NVDA screenreader"""
ip, port, valid_commands = actions.user.addon_server_endpoint()

if isinstance(commands, str):
commands = [commands]

for command in commands:
if command not in valid_commands:
raise ValueError(f"Invalid command: {command}")
Expand Down Expand Up @@ -85,7 +90,11 @@ def send_ipc_commands(commands: list[IPC_COMMAND] | IPC_COMMAND):
except:
print("Error Communicating with NVDA extension")
finally:
sock.close()
sock.close()

def send_ipc_command(command: IPC_COMMAND):
"""Sends a single command to the screenreader"""
actions.user.send_ipc_commands([command])

ORCAContext = Context()
ORCAContext.matches = r"""
Expand Down
12 changes: 12 additions & 0 deletions nvda/addon_communication/ipc_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Literal

# Exhaustive list of commands that can be sent to the NVDA addon server
IPC_COMMAND = Literal[
"disableSpeechInterruptForCharacters",
"enableSpeechInterruptForCharacters",
"disableSpeakTypedWords",
"enableSpeakTypedWords",
"disableSpeakTypedCharacters",
"enableSpeakTypedCharacters",
"debug"
]
File renamed without changes.
3 changes: 3 additions & 0 deletions nvda/debug-nvda.talon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ test reader add on:

test controller client:
user.test_controller_client()

key(ctrl-alt-shift-g):
user.test_reader_addon()
2 changes: 1 addition & 1 deletion nvda/nvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_controller_client():

def test_reader_addon():
"""Tests the reader addon"""
actions.user.send_ipc_commands(["debug"])
actions.user.send_ipc_command("debug")

ctxWindowsNVDARunning = Context()
ctxWindowsNVDARunning.matches = r"""
Expand Down

0 comments on commit 5805add

Please sign in to comment.