summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2022-08-23 15:52:56 +0200
committerOskar Nyberg <oskar@mullvad.net>2022-08-23 15:52:56 +0200
commitd700a434ca4214f931dbe180a39b6b95659fb392 (patch)
tree3ee36e9d4ca24936cbe6809d6134261dd9aa8793 /gui/src
parent7dc36e0fb75403c634c2c90c52e710ce2115248c (diff)
parent1d01a85334af7789ffd7af86e857b95b6d46ca2c (diff)
downloadmullvadvpn-d700a434ca4214f931dbe180a39b6b95659fb392.tar.xz
mullvadvpn-d700a434ca4214f931dbe180a39b6b95659fb392.zip
Merge branch 'only-disconnect-on-quit-button'
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/index.ts68
1 files changed, 25 insertions, 43 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 99aaaf5a8b..cba52d61e1 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -55,7 +55,6 @@ const linuxSplitTunneling = process.platform === 'linux' && require('./linux-spl
const windowsSplitTunneling = process.platform === 'win32' && require('./windows-split-tunneling');
enum CommandLineOptions {
- quitWithoutDisconnect = '--quit-without-disconnect',
showChanges = '--show-changes',
disableResetNavigation = '--disable-reset-navigation', // development only
}
@@ -109,8 +108,6 @@ class ApplicationMain
private macOsScrollbarVisibility?: MacOsScrollbarVisibility;
- private stayConnectedOnQuit = false;
-
private changelog?: IChangelog;
private navigationHistory?: IHistoryObject;
@@ -128,13 +125,9 @@ class ApplicationMain
this.overrideAppPaths();
- // 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(CommandLineOptions.quitWithoutDisconnect)
- ) {
- this.quitWithoutDisconnect();
+ // This ensures that only a single instance is running at the same time.
+ if (!app.requestSingleInstanceLock()) {
+ app.quit();
return;
}
@@ -168,7 +161,7 @@ class ApplicationMain
log.error(
`Render process exited with exit code ${details.exitCode} due to ${details.reason}`,
);
- this.quitWithoutDisconnect();
+ app.quit();
});
app.on('child-process-gone', (_event, details) => {
log.error(
@@ -223,14 +216,8 @@ class ApplicationMain
};
private addSecondInstanceEventHandler() {
- app.on('second-instance', (_event, argv, _workingDirectory) => {
- if (argv.includes(CommandLineOptions.quitWithoutDisconnect)) {
- // Quit if another instance is started with the quit without disconnect flag.
- this.quitWithoutDisconnect();
- } else {
- // If no action was provided to the new instance the window is opened.
- this.userInterface?.showWindow();
- }
+ app.on('second-instance', (_event, _argv, _workingDirectory) => {
+ this.userInterface?.showWindow();
});
}
@@ -287,20 +274,31 @@ class ApplicationMain
private onActivate = () => this.userInterface?.showWindow();
- private quitWithoutDisconnect() {
- this.stayConnectedOnQuit = true;
+ private async disconnectAndQuit() {
+ if (this.daemonRpc.isConnected) {
+ 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.');
+ }
+
app.quit();
}
// This is a last try to disconnect and quit gracefully if the app quits without having received
// the before-quit event.
- private onQuit = async () => {
+ private onQuit = () => {
if (this.quitStage !== AppQuitStage.ready) {
- await this.prepareToQuit();
+ this.prepareToQuit();
}
};
- private onBeforeQuit = async (event: Electron.Event) => {
+ private onBeforeQuit = (event: Electron.Event) => {
switch (this.quitStage) {
case AppQuitStage.unready:
// postpone the app shutdown
@@ -310,7 +308,7 @@ class ApplicationMain
log.info('Quit initiated');
- await this.prepareToQuit();
+ this.prepareToQuit();
// terminate the app
this.quitStage = AppQuitStage.ready;
@@ -328,23 +326,7 @@ class ApplicationMain
}
};
- private async prepareToQuit() {
- if (this.stayConnectedOnQuit) {
- log.info('Not disconnecting tunnel on quit');
- } else {
- if (this.daemonRpc.isConnected) {
- 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.');
- }
- }
-
+ private prepareToQuit() {
// Unsubscribe the event handler
try {
if (this.daemonEventListener) {
@@ -781,7 +763,7 @@ class ApplicationMain
},
);
- IpcMainEventChannel.app.handleQuit(() => app.quit());
+ IpcMainEventChannel.app.handleQuit(() => this.disconnectAndQuit());
IpcMainEventChannel.app.handleOpenUrl(async (url) => {
if (Object.values(config.links).find((link) => url.startsWith(link))) {
await shell.openExternal(url);