summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-11-10 14:43:47 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-11-22 10:51:25 +0100
commit2b31085240e32bff902816ed978dce7e7917e933 (patch)
treec20c224c67a31f293eff907f2f84be8f4250c396 /gui/src
parent414caa97a749b0b7debe1dbb2361c6ce404be8dd (diff)
downloadmullvadvpn-2b31085240e32bff902816ed978dce7e7917e933.tar.xz
mullvadvpn-2b31085240e32bff902816ed978dce7e7917e933.zip
Add support for passing --quit-without-disconnect
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/index.ts57
1 files changed, 35 insertions, 22 deletions
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