From 4a45c9fadbd479727b3cc7bb9c8b182f929f02b4 Mon Sep 17 00:00:00 2001 From: mltony Date: Sat, 30 Nov 2024 10:42:15 -0800 Subject: [PATCH] Extension point for focus or URL change --- addon/globalPlugins/browserNav/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/addon/globalPlugins/browserNav/__init__.py b/addon/globalPlugins/browserNav/__init__.py index a158c10..56f0b1d 100644 --- a/addon/globalPlugins/browserNav/__init__.py +++ b/addon/globalPlugins/browserNav/__init__.py @@ -69,6 +69,7 @@ import UIAHandler import globalVars from gui import nvdaControls +import extensionPoints debug = False if debug: @@ -670,7 +671,13 @@ def getCurrentURL(): api.getCurrentURL = getCurrentURL +api.postFocusOrURLChange = extensionPoints.Action() updateURLLock = threading.Lock() +def updateURLIfChanged(): + newURL = getFocusedURL() + if globalVars.currentURL != newURL: + api.postFocusOrURLChange.notify() + globalVars.currentURL = newURL URL_WATCH_DELAYS_MS = [300, 700, 2000, 7000] def watchURLAsync(localUpdateUrlCounter, delays=None): delays = delays or URL_WATCH_DELAYS_MS @@ -680,25 +687,22 @@ def watchURLAsync(localUpdateUrlCounter, delays=None): global globalUpdateUrlCounter if globalUpdateUrlCounter != localUpdateUrlCounter: return - globalVars.currentURL = getFocusedURL() + updateURLIfChanged() def watchURL(initialDelayMs=None): with updateURLLock: global globalUpdateUrlCounter globalUpdateUrlCounter += 1 localUpdateUrlCounter = globalUpdateUrlCounter - delays = None - if initialDelayMs is None: - globalVars.currentURL = getFocusedURL() - else: - delays = [initialDelayMs] + URL_WATCH_DELAYS_MS - utils.executeAsynchronously(watchURLAsync(localUpdateUrlCounter, delays)) + updateURLIfChanged() + utils.executeAsynchronously(watchURLAsync(localUpdateUrlCounter, None)) originalSetFocusObject = None originalVirtualBufferHandleUpdate = None def bnSetFocusObject(obj): result = originalSetFocusObject(obj) watchURL() + api.postFocusOrURLChange.notify() return result def bnVirtualBufferHandleUpdate(self):