Skip to content

Commit

Permalink
Extension point for focus or URL change
Browse files Browse the repository at this point in the history
  • Loading branch information
mltony committed Nov 30, 2024
1 parent b02a69a commit 4a45c9f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions addon/globalPlugins/browserNav/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import UIAHandler
import globalVars
from gui import nvdaControls
import extensionPoints

debug = False
if debug:
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 4a45c9f

Please sign in to comment.