Repository: nvaccess/nvda

Issue:
Launching a new copy of NVDA should exit running version and start launched version.
(Updated with command line information from Leonard).

This is a minor inconsistency, but still worth recording:

With any version of NVDA running, pressing control+alt+n restarts the installed copy of NVDA.  That works fine.

If a desktop or start menu shortcut to NVDA is instead activated, or a copy of NVDA run from File Explorer, NVDA does not restart.  NVDA does have a command line parameter -r to replace or quit the running version of NVDA and start this one (Thanks [Leonard](https://github.com/nvaccess/nvda/issues/8320#issuecomment-390983968) for reminding me of that!)

See https://www.nvaccess.org/files/nvda/documentation/userGuide.html#CommandLineOptions for more information on the command line options.

I would like to then propose that we make the -r parameter implicit and adopt that behaviour by default, and perhaps in its place add a parameter to check and return a value if there is already a copy of NVDA running to enable both functionalities going forward.



Discussion:
Hmm, in many ways what you are describing is what I get when I've just 
updated nvda and it tries to auto restart.
 I have no idea what is going on behind the scenes for this, but generally, 
I tend to relaunch with the alt/ctrl n which does close the old copy.
 Brian

bglists@blueyonder.co.uk
Sent via blueyonder.
Please address personal E-mail to:-
briang1@blueyonder.co.uk, putting 'Brian Gaff'
in the display name field.
----- Original Message ----- 
From: "Quentin Christensen" <notifications@github.com>
To: "nvaccess/nvda" <nvda@noreply.github.com>
Cc: "Subscribed" <subscribed@noreply.github.com>
Sent: Tuesday, May 22, 2018 2:15 AM
Subject: [nvaccess/nvda] Launching a new copy of NVDA should exit running 
version and start launched version. (#8320)


> This is a minor inconsistency, but still worth recording:
>
> With any version of NVDA running, pressing control+alt+n restarts the 
> installed copy of NVDA.  That works fine.
>
> If a desktop or start menu shortcut to NVDA is instead activated, or a 
> copy of NVDA run from File Explorer, NVDA does not restart.
>
> For instance, I have the latest Next snapshot installed, but I have a 
> desktop shortcut to a portable version of NVDA 2018.1.1.  In order to 
> launch that shortcut, I need to navigate to it on the desktop, press 
> NVDA+q then enter to quit the running version of NVDA, then ENTER to 
> launch the shortcut which has focus.
>
> Ideally, I should be able to have a version of NVDA running, navigate to 
> my desktop shortcut, press ENTER to activate it and then my running copy 
> of NVDA would automatically quit as the version the desktop shortcut 
> points to starts.
>
>
> -- 
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly or view it on GitHub:
> https://github.com/nvaccess/nvda/issues/8320 


The reason why NVDA restarts with the control+alt+n shortcut, is because the "-r" parameter is provided to the executable. This parameter closes a running copy of NVDA and then starts a new one. Adding the -r command line parameter should solve your issue.

Having said that, I agree that it could be considered to have this restarting behaviour by default.
That is why when I want to automate getting the log from the previously 
running version I use a batch file and avoid running the shortcut as this 
would confuse things.


Brian 


having a restart implicit could be very nice indeed.
I can support this if that is what most people would prefer. The original idea however was that  the user had to be quite specific about launching any random copy of NVDA and replacing the old one, just in case they accidentally  executed the file. 

Resolving patch:
diff --git a/source/core.py b/source/core.py
--- a/source/core.py
+++ b/source/core.py
@@ -104,7 +104,7 @@ def onResult(ID):
 			gui.runScriptModalDialog(gui.AskAllowUsageStatsDialog(None),onResult)
 
 def restart(disableAddons=False, debugLogging=False):
-	"""Restarts NVDA by starting a new copy with -r."""
+	"""Restarts NVDA by starting a new copy."""
 	if globalVars.appArgs.launcher:
 		import wx
 		globalVars.exitCode=3
@@ -114,8 +114,6 @@ def restart(disableAddons=False, debugLogging=False):
 	import winUser
 	import shellapi
 	options=[]
-	if "-r" not in sys.argv:
-		options.append("-r")
 	try:
 		sys.argv.remove('--disable-addons')
 	except ValueError:
diff --git a/source/gui/installerGui.py b/source/gui/installerGui.py
--- a/source/gui/installerGui.py
+++ b/source/gui/installerGui.py
@@ -71,10 +71,14 @@ def doInstall(createDesktopShortcut,startOnLogon,copyPortableConfig,isUpdate,sil
 			_("Success"))
 	if startAfterInstall:
 		# #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL  
-		shellapi.ShellExecute(None, None,
+		shellapi.ShellExecute(
+			None,
+			None,
 			os.path.join(installer.defaultInstallPath,'nvda.exe'),
-			u"-r",
-			None, winUser.SW_SHOWNORMAL)
+			None,
+			None,
+			winUser.SW_SHOWNORMAL
+		)
 	else:
 		wx.GetApp().ExitMainLoop()
 
@@ -379,7 +383,11 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf
 			_("Success"))
 		if startAfterCreate:
 			# #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL  
-			shellapi.ShellExecute(None, None,
+			shellapi.ShellExecute(
+				None,
+				None,
 				os.path.join(os.path.abspath(portableDirectory),'nvda.exe'),
-				u"-r",
-				None, winUser.SW_SHOWNORMAL)
+				None,
+				None,
+				winUser.SW_SHOWNORMAL
+			)
diff --git a/source/installer.py b/source/installer.py
--- a/source/installer.py
+++ b/source/installer.py
@@ -247,6 +247,9 @@ def registerInstallation(installDir,startMenuFolder,shouldCreateDesktopShortcut,
 	NVDAExe=os.path.join(installDir,u"nvda.exe")
 	slaveExe=os.path.join(installDir,u"nvda_slave.exe")
 	if shouldCreateDesktopShortcut:
+		# #8320: -r|--replace is now the default. Nevertheless, keep creating
+		# the shortcut with the now superfluous argument in case a downgrade of
+		# NVDA is later performed.
 		# Translators: The shortcut key used to start NVDA.
 		# This should normally be left as is, but might be changed for some locales
 		# if the default key causes problems for the normal locale keyboard layout.


Test patch: