Skip to content

Commit

Permalink
Support NVDA 2023.3 style device registration for automatic detection
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR committed Sep 1, 2023
1 parent 980a048 commit f97ff52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 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,7 +24,14 @@ class RemoteBrailleDisplayDriver(driver.RemoteDriver, braille.BrailleDisplayDriv
# Translators: Name for a remote braille display.
description = _("Remote Braille")
isThreadSafe = True
supportsAutomaticDetection = True
driverType = protocol.DriverType.BRAILLE
_registeredForAutoDetect: bool= False

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

def _getModifierGestures(self, model: typing.Optional[str] = None):
"""Hacky override that throws an instance at the underlying class method.
Expand Down
6 changes: 6 additions & 0 deletions addon/lib/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ def bgScanRD(


def register():
from brailleDisplayDrivers.remote import RemoteBrailleDisplayDriver
if RemoteBrailleDisplayDriver._registeredForAutoDetect:
return
bdDetect.scanForDevices.register(bgScanRD)
bdDetect.scanForDevices.moveToEnd(bgScanRD, last=False)


def unregister():
from brailleDisplayDrivers.remote import RemoteBrailleDisplayDriver
if RemoteBrailleDisplayDriver._registeredForAutoDetect:
return
bdDetect.scanForDevices.unregister(bgScanRD)

0 comments on commit f97ff52

Please sign in to comment.