Skip to content

Commit

Permalink
ipc and addon working now
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Feb 18, 2024
1 parent da1e7bc commit 08e0ba9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 12 additions & 3 deletions core/screenreader_ipc/ipc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def addon_server_endpoint() -> Tuple[str, str, str]:

def send_ipc_commands(commands: list[IPC_COMMAND]):
"""Sends a command or commands to the screenreader"""
actions.user.tts("No screenreader running to send commands to")
raise NotImplementedError

def send_ipc_command(command: IPC_COMMAND):
"""
Expand All @@ -23,6 +25,9 @@ def send_ipc_command(command: IPC_COMMAND):
function is a workaround a clearer API than passing in a list
for a single command
"""
actions.user.tts("No screenreader running to send commands to")
raise NotImplementedError


NVDAContext = Context()
NVDAContext.matches = r"""
Expand Down Expand Up @@ -62,7 +67,7 @@ def send_ipc_commands(commands: list[IPC_COMMAND]):
raise ValueError(f"Invalid command: {command}")

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(.01)
sock.settimeout(.2)
encoded = json.dumps(commands).encode()

if settings.get("user.addon_debug"):
Expand All @@ -82,13 +87,17 @@ def send_ipc_commands(commands: list[IPC_COMMAND]):
print('Received', repr(response))

if 'debug' in commands:
actions.user.tts("Sent Message to NVDA Successfully")
actions.user.tts(f"Sent Message to NVDA Successfully with server response: {response.decode('utf-8')}")

except socket.timeout as e:
print(f"NVDA Addon Connection with {ip}:{port} timed out")
print(f"Clientside connection with {ip}:{port} timed out")
print(e)
if "debug" in commands:
actions.user.tts("Clientside connection timed out")
except:
print("Error Communicating with NVDA extension")
if "debug" in commands:
actions.user.tts("Error Communicating with NVDA extension")
finally:
sock.close()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config
import tones
import globalPluginHandler
import os, json, socket, threading
import globalVars
import os, json, socket, threading, time
import globalVars, speech

# Exhaustive list of valid commands
schema = [
Expand Down Expand Up @@ -57,7 +57,7 @@ def handle_command(command: str):
elif command == "debug":
tones.beep(640, 100)

return f"Success: {command}"
return f"Success running: {command}"

class IPC_Server():
port = None
Expand Down Expand Up @@ -120,9 +120,12 @@ def create_server(self):
self.handle_client(self.client_socket)
except socket.timeout:
pass
# catch client disconnect error
except Exception as e:
print(f"\n\n\n\nTALON SERVER CRASH: {e}")
self.stop()
with open(os.path.join(globalVars.appArgs.configPath, "talon_server_error.log"), "w") as f:
f.write(str(e))
break
finally:
if self.client_socket:
Expand Down

0 comments on commit 08e0ba9

Please sign in to comment.