Skip to content

Commit

Permalink
clean up old files
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Feb 15, 2024
1 parent 0f77c0e commit 09972d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 104 deletions.
11 changes: 5 additions & 6 deletions core/addon_communication/ipc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ 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[str] | str):
def send_ipc_commands(commands: list[IPC_COMMAND] | IPC_COMMAND):
"""Sends a command or commands to the screenreader"""


NVDAContext = Context()
NVDAContext.matches = r"""
tag: user.nvda_running
Expand All @@ -25,7 +24,7 @@ def send_ipc_commands(commands: list[str] | str):
class NVDAActions:

def addon_server_endpoint() -> Tuple[str, str, str]:
"""Returns the address and port of the addon server"""
"""Returns the address, port, and valid commands for the addon server"""
SPEC_FILE = os.path.expanduser("~\\AppData\\Roaming\\nvda\\talon_server_spec.json")

with open(SPEC_FILE, "r") as f:
Expand All @@ -41,12 +40,12 @@ def addon_server_endpoint() -> Tuple[str, str, str]:
ip = ipaddress.ip_address(address)
assert ip.is_private, "Address is not a local IP address"
except ValueError:
raise ValueError(f"Invalid IP address: {address}")
raise ValueError(f"Invalid NVDA IP address: {address}")

return address, port, valid_commands


def send_ipc_commands(commands: list[str] | str):
def send_ipc_commands(commands: list[IPC_COMMAND] | 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()

Expand All @@ -65,7 +64,7 @@ def send_ipc_commands(commands: list[str] | str):
print(f"Sending {commands} to {ip}:{port}")

# Although the screenreader server will block while processing commands,
# having a lock clientside reduces errors when sending multiple commands
# having a lock client-side prevents errors when sending multiple commands
with lock:
try:
sock.connect((ip, int(port)))
Expand Down
50 changes: 0 additions & 50 deletions core/addon_communication/ipc_helpers.py

This file was deleted.

44 changes: 6 additions & 38 deletions core/addon_communication/ipc_schema.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
# import dataclasses
from typing import Optional, Union, Literal
# import json
from typing import Literal

# List of all valid commands that can be sent to the screenreader
IPC_COMMAND = Literal[
# Prevent the screenreader from interrupting echoback
"disableSpeechInterruptForCharacters",
"enableSpeechInterruptForCharacters",

# Prevent the screenreader from interrupting echoback
"disableSpeakTypedWords",
"enableSpeakTypedWords",

# Prevent the screenreader from speaking unnecessary characters in addition to full echo back
"disableSpeakTypedCharacters",
"enableSpeakTypedCharacters"

# Play a sound to confirm that the command was received
"debug"
]

# @dataclasses.dataclass
# class IPC_Setting_Change:
# setting_name: str
# setting_value: Union[str, int, float, bool]

# def validate(self):
# if not isinstance(self.setting_name, str):
# raise TypeError(f"Invalid setting name type: {type(self.setting_name)}")
# if not isinstance(self.setting_value, (str, int, float, bool)):
# raise TypeError(f"Invalid setting value type: {type(self.setting_value)}")

# @dataclasses.dataclass
# class IPC_Action:
# action_name: str
# action_args: Optional[list[str]]

# def validate(self):
# if not isinstance(self.action_name, str):
# raise TypeError(f"Invalid action name type: {type(self.action_name)}")
# if self.action_args is not None and not isinstance(self.action_args, list):
# raise TypeError(f"Invalid action args type: {type(self.action_args)}")

# class IPC_Payload
# def __init__(self, commands: list[Union[IPC_Setting_Change, IPC_Action]]):
# self.commands = commands

# def validate(self):
# for command in self.commands:
# if not isinstance(command, (IPC_Setting_Change, IPC_Action)):
# raise TypeError(f"Invalid command type: {type(command)}")

# def serialize(self):
# return json.dumps([dataclasses.asdict(command) for command in self.commands])

2 changes: 0 additions & 2 deletions nvda/nvda-settings.talon

This file was deleted.

10 changes: 2 additions & 8 deletions nvda/nvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ def is_nvda_running() -> bool:
else:
if settings.get("user.addon_debug"):
print(f"NVDA not running. Client response value: {client_response}")
# if client_response == 1717:
# # reload the dll if there is an error
# print("Reloading NVDA dll")
# ctypes.windll.kernel32.FreeLibrary(nvda_client._handle)
# nvda_client: ctypes.WinDLL = ctypes.windll.LoadLibrary(dll_path)
# return nvda_client.nvdaController_testIfRunning()
# else:
return False


Expand Down Expand Up @@ -150,6 +143,7 @@ def disable_interrupt(_):
SPEC_FILE = os.path.expanduser("~\\AppData\\Roaming\\nvda\\talon_server_spec.json")
if not os.path.exists(SPEC_FILE):
return
# bundle the commands into a single message
commands = ["disableSpeechInterruptForCharacters",
"disableSpeakTypedWords",
"disableSpeakTypedCharacters"
Expand All @@ -162,7 +156,7 @@ def restore_interrupt_setting(_):
SPEC_FILE = os.path.expanduser("~\\AppData\\Roaming\\nvda\\talon_server_spec.json")
if not os.path.exists(SPEC_FILE):
return

# bundle the commands into a single message
commands = ["enableSpeechInterruptForCharacters",
"enableSpeakTypedWords",
"enableSpeakTypedCharacters"
Expand Down

0 comments on commit 09972d2

Please sign in to comment.