This repository was archived by the owner on Mar 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Enable modification of NVDA settings in automation #14
Draft
jugglinmike
wants to merge
22
commits into
main
Choose a base branch
from
nvda-configuration-server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bfba2b6
Centralize installation logic & reduce admin reqs
jugglinmike bd2abd4
PARTIAL: Port uninstall logic to C++
jugglinmike bb1bf3b
PARTIAL: Continue porting uninstall logic to C++
jugglinmike b78c844
Remove directory during un-install script
jugglinmike 8af6517
Complete re-implementation
jugglinmike 599a05b
Report operation result
jugglinmike 5394e33
Simplify types
jugglinmike 38e88f6
Remove unused code
jugglinmike 32ad8ec
Remove reference to non-existent directory
jugglinmike b57956b
Remove unused Node.js package
jugglinmike 9bca7ab
Define enum to avoid boolean trap and fix bug
jugglinmike 7e70fea
PARTIAL Introduce NVDA add-on for config mgmt
jugglinmike 6fd5ed3
Complete initial implementation
jugglinmike 2144024
PARTIAL Integrate NVDA plugin and at-driver CLI
jugglinmike 04b1525
Relocate NVDA plugin installation logic
jugglinmike 61cfc6e
Centralize definition of nvda-addon's default port
jugglinmike 9a70ddd
Make the TCP port of the NVDA add-on configurable
jugglinmike ceef813
Improve structure of NVDA add-on's Python modules
jugglinmike b56987f
Remove debugging code
jugglinmike e518271
Reorganize code for NVDA add-on
jugglinmike 895df18
Reorganize source files for at-driver
jugglinmike fc29d28
Force WebSocket clients to specify AT under test
jugglinmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,3 +200,5 @@ FakesAssemblies/ | |
# Custom ignores | ||
gallery.xml | ||
project.lock.json | ||
|
||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../lib/cli')(process); | ||
require('../lib/at-driver/cli')(process); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
const http = require('http'); | ||
|
||
/** | ||
* Transmit JSON-formatted UTF-8 encoded data via an HTTP POST request. | ||
* | ||
* @param {number} port - the TCP port on which to send the data | ||
* @param {object} body - the data to send | ||
*/ | ||
module.exports = function postJSON(port, body) { | ||
return new Promise((resolve, reject) => { | ||
const postData = JSON.stringify(body); | ||
const request = http.request( | ||
{ | ||
hostname: 'localhost', | ||
method: 'POST', | ||
port, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': Buffer.byteLength(postData) | ||
} | ||
}, | ||
(response) => { | ||
let responseBody = ''; | ||
response.setEncoding('utf-8'); | ||
response.on('data', (chunk) => responseBody += chunk); | ||
response.on('end', () => { | ||
if (!response.complete) { | ||
reject(new Error('HTTP response interrupted')); | ||
return; | ||
} | ||
|
||
if (response.statusCode >= 300) { | ||
reject(new Error(responseBody)); | ||
return; | ||
} | ||
|
||
resolve(); | ||
}); | ||
} | ||
); | ||
|
||
request.on('error', reject); | ||
request.write(postData); | ||
request.end(); | ||
}); | ||
}; |
55 changes: 55 additions & 0 deletions
55
lib/nvda-configuration-server/globalPlugins/nvda-config-server/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from threading import Thread | ||
|
||
import addonHandler | ||
import config | ||
import globalPluginHandler | ||
|
||
from .host_location import HOST_NAME, HOST_PORT | ||
from .config_server import ConfigServer, ConfigHandler | ||
|
||
try: | ||
ADDON_NAME = addonHandler.getCodeAddon().name | ||
except addonHandler.AddonError: | ||
ADDON_NAME = 'scratch-nvda-config-server' | ||
|
||
def update_dictlike(dictlike, values): | ||
for key, value in values.items(): | ||
if hasattr(dictlike[key], '__setitem__'): | ||
update_dictlike(dictlike[key], value) | ||
else: | ||
dictlike[key] = value | ||
|
||
class GlobalPlugin(globalPluginHandler.GlobalPlugin): | ||
def __init__(self, *args, **kwargs): | ||
super(GlobalPlugin, self).__init__(*args, **kwargs) | ||
def on_get(): | ||
return self.dict() | ||
def on_post(body): | ||
self.update(body) | ||
self.server = ConfigServer(on_get, on_post, (HOST_NAME, HOST_PORT), ConfigHandler) | ||
self.server_thread = Thread(target=self.server.serve_forever, daemon=True) | ||
self.server_thread.start() | ||
self.profile_to_restore = config.conf.profiles[-1].name | ||
|
||
def terminate(self, *args, **kwargs): | ||
self.server.shutdown() | ||
self.server.server_close() | ||
self.server_thread.join() | ||
config.conf.manualActivateProfile(self.profile_to_restore) | ||
super().terminate(*args, **kwargs) | ||
|
||
@property | ||
def config(self): | ||
profile = config.conf.profiles[-1].name | ||
if profile != ADDON_NAME: | ||
self.profile_to_restore = profile | ||
if ADDON_NAME not in config.conf.listProfiles(): | ||
config.conf.createProfile(ADDON_NAME) | ||
config.conf.manualActivateProfile(ADDON_NAME) | ||
return config.conf | ||
|
||
def dict(self): | ||
return self.config.dict() | ||
|
||
def update(self, values): | ||
update_dictlike(self.config, values) |
39 changes: 39 additions & 0 deletions
39
lib/nvda-configuration-server/globalPlugins/nvda-config-server/config_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
import json | ||
import sys | ||
|
||
class ConfigServer(HTTPServer): | ||
def __init__(self, on_get, on_post, *args, **kwargs): | ||
super(ConfigServer, self).__init__(*args, **kwargs) | ||
self.on_get = on_get | ||
self.on_post = on_post | ||
|
||
class ConfigHandler(BaseHTTPRequestHandler): | ||
def do_GET(self): | ||
try: | ||
body = bytes(json.dumps(self.server.on_get()), 'utf-8') | ||
except: | ||
self.send_response(500) | ||
self.end_headers() | ||
self.wfile.write(bytes('Error: "{}"'.format(sys.exc_info()[1]), 'utf-8')) | ||
return | ||
|
||
self.send_response(200) | ||
self.send_header('Content-type', 'text/json') | ||
self.end_headers() | ||
self.wfile.write(body) | ||
|
||
def do_POST(self): | ||
try: | ||
content_length = int(self.headers['Content-Length']) | ||
body = json.loads(self.rfile.read(content_length)) | ||
self.server.on_post(body) | ||
except: | ||
self.send_response(500) | ||
self.end_headers() | ||
self.wfile.write(bytes('Error: "{}"'.format(sys.exc_info()[1]), 'utf-8')) | ||
return | ||
|
||
self.send_response(200) | ||
self.end_headers() | ||
self.wfile.write('ok') |
20 changes: 20 additions & 0 deletions
20
lib/nvda-configuration-server/globalPlugins/nvda-config-server/host_location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import json | ||
import os | ||
|
||
HOST_NAME = 'localhost' | ||
|
||
try: | ||
HOST_PORT = int(os.environ['NVDA_CONFIGURATION_SERVER_PORT']) | ||
except KeyError: | ||
# The installation procedure inserts this file from the project's "shared" | ||
# directory. | ||
filename = os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), | ||
'..', | ||
'..', | ||
'shared', | ||
'default-at-configuration-port.json' | ||
) | ||
|
||
with open(filename, 'r') as handle: | ||
HOST_PORT = json.loads(handle.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = configuration-server | ||
summary = "Interact with NVDA's configuration via a local HTTP server" | ||
description = """This add-on exposes the configuration of the running NVDA process via a public interface so that external tools can modify that configuration on-the-fly. The TCP port in use by the HTTP server can be specified via the NVDA_CONFIGURATION_SERVER_PORT environment variable.""" | ||
author = "Bocoup LLC" | ||
url = https://bocoup.com | ||
version = 0.0.1 | ||
minimumNVDAVersion = 2021.3 | ||
lastTestedNVDAVersion = 2021.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7658 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the file just the port? |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.\Release\MakeVoice.exe || exit /b | ||
|
||
:: Install the project's custom NVDA add-on. | ||
:: | ||
:: This operation is somewhat fragile (in that it may be broken by future | ||
:: releases of NVDA) because it assumes the location and format of the screen | ||
:: reader's "add on" directory. Although it would be preferable to first | ||
:: "package" the add-on and then install it using the same procedure as an | ||
:: end-user, that approach requires manual interaction with a modal dialog and | ||
:: is therefore inappropriate for the needs of this project. | ||
|
||
set destination=%USERPROFILE%\AppData\Roaming\nvda\addons\nvda-configuration-server | ||
|
||
IF EXIST %destination% rmdir /Q /S %destination% || exit /b | ||
|
||
:: In some environments, the "mkdir" command may be capable of creating | ||
:: non-existent intermediate directories in the input path. This is dependent | ||
:: on the presence of "Command Extensions". Create each directory individually | ||
:: to support environments where Command Extensions are not enabled. | ||
mkdir %USERPROFILE%\AppData | ||
mkdir %USERPROFILE%\AppData\Roaming | ||
mkdir %USERPROFILE%\AppData\Roaming\nvda | ||
mkdir %USERPROFILE%\AppData\Roaming\nvda\addons | ||
mkdir %destination% || exit /b | ||
|
||
xcopy /E /Y .\lib\nvda-configuration-server %destination% || exit /b | ||
|
||
xcopy /E /Y .\lib\shared %destination%\shared\ || exit /b |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the nesting can be reduced some to be easier to read.