diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-22 10:51:44 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-11-22 10:51:44 +0100 |
| commit | bde1bb119f09d43f11cb720916a54e84f717a685 (patch) | |
| tree | 00bfe56bef326cfc3269451b8addb1076b441d47 | |
| parent | 414caa97a749b0b7debe1dbb2361c6ce404be8dd (diff) | |
| parent | f8f7bc1956226dbbc788afb6b258e0ff99bd4528 (diff) | |
| download | mullvadvpn-bde1bb119f09d43f11cb720916a54e84f717a685.tar.xz mullvadvpn-bde1bb119f09d43f11cb720916a54e84f717a685.zip | |
Merge branch 'fix-windows-double-icon-on-update'
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | dist-assets/windows/installer.nsh | 39 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 57 |
3 files changed, 58 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 397659152f..fea6f8d5c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Line wrap the file at 100 chars. Th #### Windows - Fix app size after changing display scale. - Fix daemon not starting if all excluded app paths reside on non-existent/unmounted volumes. +- Remove tray icon of current running app version when upgrading. ## [2021.6] - 2021-11-17 diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh index c1dac59bf8..402802e1dc 100644 --- a/dist-assets/windows/installer.nsh +++ b/dist-assets/windows/installer.nsh @@ -911,29 +911,32 @@ # The default behavior may cause the daemon to disconnect. # !macro customCheckAppRunning + push $R0 + push $R1 # This must be done here for compatibility with <= 2021.2, # since those versions do not kill the GUI in the uninstaller. - # This is fine as long as /f is used. - - ${KillGui} - -!macroend - -# -# KillGui -# -# Kill "Mullvad VPN.exe" if it is running. Killing without /f may cause the daemon to disconnect. -# -!macro KillGui + Var /GLOBAL OldVersion + ReadRegStr $OldVersion HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APP_GUID}" "DisplayVersion" + StrCpy $R0 $OldVersion 4 # Major version + StrCpy $R1 $OldVersion 1 5 # Minor version + ${If} $R0 > 2021 + Goto customCheckAppRunning_skip_kill + ${OrIf} $R0 == 2021 + ${If} $R1 > 2 + Goto customCheckAppRunning_skip_kill + ${EndIf} + ${EndIf} + # Killing without /f will likely cause the daemon to disconnect. nsExec::Exec `taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}"` $R0 - Sleep 500 -!macroend + customCheckAppRunning_skip_kill: + pop $R1 + pop $R0 -!define KillGui '!insertmacro "KillGui"' +!macroend # # customInstall @@ -1231,6 +1234,10 @@ Pop $FullUninstall + nsExec::Exec '"$INSTDIR\Mullvad VPN.exe" --quit-without-disconnect' $0 + Sleep 500 + nsExec::Exec `taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}"` $0 + ${If} $FullUninstall == 0 # Save the target tunnel state if we're upgrading nsExec::ExecToStack '"$TEMP\mullvad-setup.exe" prepare-restart' @@ -1251,8 +1258,6 @@ Goto customRemoveFiles_abort ${EndIf} - ${KillGui} - # Remove application files log::Log "Deleting $INSTDIR" RMDir /r $INSTDIR diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 3e8a7a34ee..0916a18166 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -98,6 +98,8 @@ const SANDBOX_DISABLED = app.commandLine.hasSwitch('no-sandbox'); const ALLOWED_PERMISSIONS = ['clipboard-sanitized-write']; +const QUIT_WITHOUT_DISCONNECT_FLAG = '--quit-without-disconnect'; + enum AppQuitStage { unready, initiated, @@ -245,6 +247,8 @@ class ApplicationMain { private macOsScrollbarVisibility?: MacOsScrollbarVisibility; + private quitWithoutDisconnect = false; + public run() { // Remove window animations to combat window flickering when opening window. Can be removed when // this issue has been resolved: https://github.com/electron/electron/issues/12130 @@ -254,10 +258,16 @@ class ApplicationMain { this.overrideAppPaths(); - if (this.ensureSingleInstance()) { + // This ensures that only a single instance is running at the same time, but also exits if + // there's no already running instance when the quit without disconnect flag is supplied. + if (!app.requestSingleInstanceLock() || process.argv.includes(QUIT_WITHOUT_DISCONNECT_FLAG)) { + this.quitWithoutDisconnect = true; + app.quit(); return; } + this.addSecondInstanceEventHandler(); + this.initLogging(); log.debug(`Chromium sandbox is ${SANDBOX_DISABLED ? 'disabled' : 'enabled'}`); @@ -287,18 +297,17 @@ class ApplicationMain { app.on('before-quit', this.onBeforeQuit); } - private ensureSingleInstance() { - if (app.requestSingleInstanceLock()) { - app.on('second-instance', (_event, _commandLine, _workingDirectory) => { - if (this.windowController) { - this.windowController.show(); - } - }); - return false; - } else { - app.quit(); - return true; - } + private addSecondInstanceEventHandler() { + app.on('second-instance', (_event, argv, _workingDirectory) => { + if (argv.includes(QUIT_WITHOUT_DISCONNECT_FLAG)) { + // Quit if another instance is started with the quit without disconnect flag. + this.quitWithoutDisconnect = true; + app.quit(); + } else if (this.windowController) { + // If no action was provided to the new instance the window is opened. + this.windowController.show(); + } + }); } private overrideAppPaths() { @@ -377,16 +386,20 @@ class ApplicationMain { }; private async prepareToQuit() { - if (this.connectedToDaemon) { - try { - await this.daemonRpc.disconnectTunnel(); - log.info('Disconnected the tunnel'); - } catch (e) { - const error = e as Error; - log.error(`Failed to disconnect the tunnel: ${error.message}`); - } + if (this.quitWithoutDisconnect) { + log.info('Not disconnecting tunnel on quit'); } else { - log.info('Cannot close the tunnel because there is no active connection to daemon.'); + if (this.connectedToDaemon) { + try { + await this.daemonRpc.disconnectTunnel(); + log.info('Disconnected the tunnel'); + } catch (e) { + const error = e as Error; + log.error(`Failed to disconnect the tunnel: ${error.message}`); + } + } else { + log.info('Cannot close the tunnel because there is no active connection to daemon.'); + } } // Unsubscribe the event handler |
