Skip to content

Commit

Permalink
Merge branch 'master' into controlTypes-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Jun 15, 2021
2 parents 61ec5eb + 0d98162 commit 50f88e5
Show file tree
Hide file tree
Showing 50 changed files with 3,586 additions and 2,133 deletions.
24 changes: 17 additions & 7 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def onResult(ID):

@dataclass
class NewNVDAInstance:
filePath: Optional[str] = None
filePath: str
parameters: Optional[str] = None
directory: Optional[str] = None

Expand All @@ -124,7 +124,8 @@ def restart(disableAddons=False, debugLogging=False):
"""Restarts NVDA by starting a new copy."""
if globalVars.appArgs.launcher:
globalVars.exitCode=3
triggerNVDAExit()
if not triggerNVDAExit():
log.error("NVDA already in process of exiting, this indicates a logic error.")
return
import subprocess
for paramToRemove in ("--disable-addons", "--debug-logging", "--ease-of-access"):
Expand All @@ -140,11 +141,12 @@ def restart(disableAddons=False, debugLogging=False):
if debugLogging:
options.append('--debug-logging')

triggerNVDAExit(NewNVDAInstance(
if not triggerNVDAExit(NewNVDAInstance(
sys.executable,
subprocess.list2cmdline(options + sys.argv[1:]),
globalVars.appDir
))
)):
log.error("NVDA already in process of exiting, this indicates a logic error.")


def resetConfiguration(factoryDefaults=False):
Expand Down Expand Up @@ -263,10 +265,11 @@ def _doShutdown(newNVDA: Optional[NewNVDAInstance]):
_startNewInstance(newNVDA)


def triggerNVDAExit(newNVDA: Optional[NewNVDAInstance] = None):
def triggerNVDAExit(newNVDA: Optional[NewNVDAInstance] = None) -> bool:
"""
Used to safely exit NVDA. If a new instance is required to start after exit, queue one by specifying
instance information with `newNVDA`.
@return: True if this is the first call to trigger the exit, and the shutdown event was queued.
"""
import queueHandler
global _hasShutdownBeenTriggered
Expand All @@ -275,8 +278,11 @@ def triggerNVDAExit(newNVDA: Optional[NewNVDAInstance] = None):
# queue this so that the calling process can exit safely (eg a Popup menu)
queueHandler.queueFunction(queueHandler.eventQueue, _doShutdown, newNVDA)
_hasShutdownBeenTriggered = True
log.debug("_doShutdown has been queued")
return True
else:
log.debugWarning("NVDA exit has already been triggered")
log.debug("NVDA has already been triggered to exit safely.")
return False


def _closeAllWindows():
Expand Down Expand Up @@ -712,7 +718,11 @@ def _doPostNvdaStartupAction():
log.info("Exiting")
# If MainLoop is terminated through WM_QUIT, such as starting an NVDA instance older than 2021.1,
# triggerNVDAExit has not been called yet
triggerNVDAExit()
if triggerNVDAExit():
log.debug(
"NVDA not already exiting, hit catch-all exit trigger."
" This likely indicates NVDA is exiting due to WM_QUIT."
)
_terminate(gui)
config.saveOnExit()

Expand Down
6 changes: 4 additions & 2 deletions source/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def onExitCommand(self, evt):
d.Show()
self.postPopup()
else:
core.triggerNVDAExit()
if not core.triggerNVDAExit():
log.error("NVDA already in process of exiting, this indicates a logic error.")

def onNVDASettingsCommand(self,evt):
self._popupSettingsDialog(NVDASettingsDialog)
Expand Down Expand Up @@ -693,7 +694,8 @@ def onOk(self, evt):
if action >= 2 and config.isAppX:
action += 1
if action == 0:
core.triggerNVDAExit()
if not core.triggerNVDAExit():
log.error("NVDA already in process of exiting, this indicates a logic error.")
return # there's no need to destroy ExitDialog in this instance as triggerNVDAExit will do this
elif action == 1:
queueHandler.queueFunction(queueHandler.eventQueue,core.restart)
Expand Down
18 changes: 13 additions & 5 deletions source/gui/installerGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ def doInstall(

newNVDA = None
if startAfterInstall:
newNVDA = core.NewNVDAInstance(os.path.join(installer.defaultInstallPath, 'nvda.exe'))
core.triggerNVDAExit(newNVDA)
newNVDA = core.NewNVDAInstance(
filePath=os.path.join(installer.defaultInstallPath, 'nvda.exe'),
parameters=f"--log-level={log.level}"
)
if not core.triggerNVDAExit(newNVDA):
log.error("NVDA already in process of exiting, this indicates a logic error.")


def doSilentInstall(
Expand Down Expand Up @@ -260,7 +264,7 @@ def onInstall(self, evt):
createDesktopShortcut=self.createDesktopShortcutCheckbox.Value,
startOnLogon=self.startOnLogonCheckbox.Value,
copyPortableConfig=self.copyPortableConfigCheckbox.Value,
silent=self.isUpdate
isUpdate=self.isUpdate
)
wx.GetApp().ScheduleForDestruction(self)

Expand Down Expand Up @@ -467,5 +471,9 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf
if silent or startAfterCreate:
newNVDA = None
if startAfterCreate:
newNVDA = core.NewNVDAInstance(os.path.join(portableDirectory, 'nvda.exe'))
core.triggerNVDAExit(newNVDA)
newNVDA = core.NewNVDAInstance(
filePath=os.path.join(portableDirectory, 'nvda.exe'),
parameters=f"--log-level={log.level}"
)
if not core.triggerNVDAExit(newNVDA):
log.error("NVDA already in process of exiting, this indicates a logic error.")
6 changes: 4 additions & 2 deletions source/gui/startupDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ def onContinueRunning(self, evt):
self.Destroy()
core.doStartupDialogs()

def onExit(self, evt):
core.triggerNVDAExit()
def onExit(self, evt: wx.CommandEvent):
if not core.triggerNVDAExit():
log.error("NVDA already in process of exiting, this indicates a logic error.")
self.Destroy() # Without this, the onExit is called multiple times by wx.

@classmethod
def run(cls):
Expand Down
Loading

0 comments on commit 50f88e5

Please sign in to comment.