@@ -419,85 +419,30 @@ def _handleNVDAModuleCleanupBeforeGUIExit():
419419 brailleViewer .destroyBrailleViewer ()
420420
421421
422- def _pollForForegroundHWND () -> int :
423- """
424- @note: The foreground window should usually be fetched on the first try,
425- however it may take longer if Windows is taking a long time changing window focus.
426- Times out after 20 seconds (MAX_WAIT_TIME_SECS).
427- After timing out, NVDA will give up trying to start and exit.
428- """
429- import ui
430- from utils .blockUntilConditionMet import blockUntilConditionMet
431- import winUser
432-
433- # winUser.getForegroundWindow may return NULL in certain circumstances,
434- # such as when a window is losing activation.
435- # This should not remain the case for an extended period of time.
436- # If NVDA is taking longer than expected to fetch the foreground window, perform a warning.
437- # We must wait a long time after this warning to
438- # allow for braille / speech to be understood before exiting.
439- # Unfortunately we cannot block with a dialog as NVDA cannot read dialogs yet.
440- WARN_AFTER_SECS = 5
441- MAX_WAIT_TIME_SECS = 20
442-
443- success , foregroundHWND = blockUntilConditionMet (
444- getValue = winUser .getForegroundWindow ,
445- giveUpAfterSeconds = WARN_AFTER_SECS ,
446- )
447- if success :
448- return foregroundHWND
449-
450- exitAfterWarningSecs = MAX_WAIT_TIME_SECS - WARN_AFTER_SECS
451- ui .message (_ (
452- # Translators: Message when NVDA is having an issue starting up
453- "NVDA is failing to fetch the foreground window. "
454- "If this continues, NVDA will quit starting in %d seconds." % exitAfterWarningSecs
455- ))
456-
457- success , foregroundHWND = blockUntilConditionMet (
458- getValue = winUser .getForegroundWindow ,
459- giveUpAfterSeconds = exitAfterWarningSecs ,
460- )
461- if success :
462- return foregroundHWND
463- log .critical ("NVDA could not fetch the foreground window. Exiting NVDA." )
464- # Raising exception here causes core.main to exit and NVDA to fail to start
465- raise NVDANotInitializedError ("Could not fetch foreground window" )
466-
467-
468422def _initializeObjectCaches ():
469423 """
470424 Caches the desktop object.
471425 This may make information from the desktop window available on the lock screen,
472426 however no known exploit is known for this.
473427 2023.1 plans to ensure the desktopObject is available only when signed-in.
474428
475- Also initializes other object caches to the foreground window.
476- Previously the object that was cached was the desktopObject,
477- however this may leak secure information to the lock screen.
478- The foreground window is set as the object cache,
479- as the foreground window would already be accessible on the lock screen (e.g. Magnifier).
480- It also is more intuitive that NVDA focuses the foreground window,
481- as opposed to the desktop object.
482-
483- @note: The foreground window should usually be fetched on the first try,
484- however it may take longer if Windows is taking a long time changing window focus.
485- Times out after 20 seconds (MAX_WAIT_TIME_SECS in _pollForForegroundHWND).
486- After timing out, NVDA will give up trying to start and exit.
429+ The desktop object must be used, as setting the object caches has side effects,
430+ such as focus events.
431+ Side effects from objects may require NVDA to be finished initializing.
432+ The desktop object is an NVDA object without custom code associated with it.
487433 """
488434 import api
489435 import NVDAObjects
436+ from winAPI .sessionTracking import _IgnoreWindowsLockState
490437 import winUser
491438
492439 desktopObject = NVDAObjects .window .Window (windowHandle = winUser .getDesktopWindow ())
493- api .setDesktopObject (desktopObject )
494-
495- foregroundHWND = _pollForForegroundHWND ()
496- foregroundObject = NVDAObjects .window .Window (windowHandle = foregroundHWND )
497- api .setForegroundObject (foregroundObject )
498- api .setFocusObject (foregroundObject )
499- api .setNavigatorObject (foregroundObject )
500- api .setMouseObject (foregroundObject )
440+ with _IgnoreWindowsLockState ():
441+ api .setDesktopObject (desktopObject )
442+ api .setForegroundObject (desktopObject )
443+ api .setFocusObject (desktopObject )
444+ api .setNavigatorObject (desktopObject )
445+ api .setMouseObject (desktopObject )
501446
502447
503448def main ():
0 commit comments