Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NVDA 2023.3 style device registration for automatic detection #11

Merged
merged 7 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions addon/brailleDisplayDrivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from logHandler import log

if typing.TYPE_CHECKING:
from ..lib import detection
from ..lib import driver
from ..lib import protocol
else:
addon: addonHandler.Addon = addonHandler.getCodeAddon()
detection = addon.loadModule("lib.detection")
driver = addon.loadModule("lib.driver")
protocol = addon.loadModule("lib.protocol")

Expand All @@ -22,8 +24,13 @@ class RemoteBrailleDisplayDriver(driver.RemoteDriver, braille.BrailleDisplayDriv
# Translators: Name for a remote braille display.
description = _("Remote Braille")
isThreadSafe = True
supportsAutomaticDetection = True
driverType = protocol.DriverType.BRAILLE

@classmethod
def registerAutomaticDetection(cls, driverRegistrar):
driverRegistrar.addDeviceScanner(detection.bgScanRD, moveToStart=True)

def _getModifierGestures(self, model: typing.Optional[str] = None):
"""Hacky override that throws an instance at the underlying class method.
If we don't do this, the method can't acces the gesture map at the instance level.
Expand Down
24 changes: 17 additions & 7 deletions addon/globalPlugins/rdAccess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from utils.security import isRunningOnSecureDesktop
from IAccessibleHandler import SecureDesktopNVDAObject
from .secureDesktopHandling import SecureDesktopHandler
import versionInfo

if typing.TYPE_CHECKING:
from ...lib import (
Expand All @@ -44,6 +45,8 @@
rdPipe = addon.loadModule("lib.rdPipe")
secureDesktop = addon.loadModule("lib.secureDesktop")

supportsBrailleAutoDetectRegistration = (versionInfo.version_year, versionInfo.version_major) >= (2023, 3)


class RDGlobalPlugin(globalPluginHandler.GlobalPlugin):
_synthDetector: typing.Optional[_SynthDetector] = None
Expand Down Expand Up @@ -105,10 +108,11 @@ def _registerRdPipeInRegistry(cls):
atexit.register(cls._unregisterRdPipeFromRegistry)

def initializeOperatingModeServer(self):
detection.register()
if configuration.getRecoverRemoteSpeech():
self._synthDetector = _SynthDetector()
self._triggerBackgroundDetectRescan(True)
if not supportsBrailleAutoDetectRegistration:
detection.register()
self._triggerBackgroundDetectRescan(rescanBraille=not supportsBrailleAutoDetectRegistration, force=True)
if not isRunningOnSecureDesktop():
post_sessionLockStateChanged.register(self._handleLockStateChanged)

Expand Down Expand Up @@ -191,9 +195,10 @@ def _handleNewPipe(self, action: directoryChanges.FileNotifyInformationAction, f
def terminateOperatingModeServer(self):
if not isRunningOnSecureDesktop():
post_sessionLockStateChanged.unregister(self._handleLockStateChanged)
if not supportsBrailleAutoDetectRegistration:
detection.unregister()
if self._synthDetector:
self._synthDetector.terminate()
detection.unregister()

def terminateOperatingModeRdClient(self):
if isRunningOnSecureDesktop():
Expand Down Expand Up @@ -308,13 +313,18 @@ def _handlePostConfigProfileSwitch(self): # NOQA: C901

def _handleLockStateChanged(self, isNowLocked):
if not isNowLocked:
self._triggerBackgroundDetectRescan(True)
self._triggerBackgroundDetectRescan(force=True)

def _triggerBackgroundDetectRescan(self, force: bool = False):
if self._synthDetector:
def _triggerBackgroundDetectRescan(
self,
rescanSpeech: bool = True,
rescanBraille: bool = True,
force: bool = False
):
if rescanSpeech and self._synthDetector:
self._synthDetector.rescan(force)
detector = braille.handler._detector
if detector is not None:
if rescanBraille and detector is not None:
detector.rescan(
usb=detector._detectUsb,
bluetooth=detector._detectBluetooth,
Expand Down
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _(arg):
# Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional)
"addon_minimumNVDAVersion": "2023.2",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2023.2",
"addon_lastTestedNVDAVersion": "2023.3",
# Add-on update channel (default is None, denoting stable releases,
# and for development releases, use "dev".)
# Do not change unless you know what you are doing!
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ This enables a user experience where managing a remote system feels just as perf
* Ability to use speech and braille from the user session when accessing secure desktops

## Changelog
### Version 1.1

- Added support for NVDA 2023.3 style device registration for automatic detection of braille displays [#11](https://github.com/leonardder/rdAccess/pull/11)

### Version 1.0

Expand Down