From 63dda8903519c93df893bf174c90ee3a6dad2d86 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 28 Mar 2017 09:39:23 -0400 Subject: [PATCH] fix(GUI): prevent blank application when sending SIGINT (#1220) This issue only affects GNU/Linux and macOS. If the user sends SIGINT to the application, the main process dies, but we get an orphaned blank browser window. The problem only seems to occur when there is a `beforeunload` window event handlers, which we use to warn the user when quitting while flashing. Change-Type: patch Changelog-Entry: Prevent blank application when sending SIGINT on GNU/Linux and macOS. Fixes: https://github.com/resin-io/etcher/issues/1028 Signed-off-by: Juan Cruz Viotti --- lib/gui/etcher.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/gui/etcher.js b/lib/gui/etcher.js index aad2cac0..7ee51c79 100644 --- a/lib/gui/etcher.js +++ b/lib/gui/etcher.js @@ -19,10 +19,21 @@ const electron = require('electron'); const _ = require('lodash'); const path = require('path'); +const EXIT_CODES = require('../shared/exit-codes'); let mainWindow = null; electron.app.on('window-all-closed', electron.app.quit); +// Sending a `SIGINT` (e.g: Ctrl-C) to an Electron app that registers +// a `beforeunload` window event handler results in a disconnected white +// browser window in GNU/Linux and macOS. +// The `before-quit` Electron event is triggered in `SIGINT`, so we can +// make use of it to ensure the browser window is completely destroyed. +// See https://github.com/electron/electron/issues/5273 +electron.app.on('before-quit', () => { + process.exit(EXIT_CODES.SUCCESS); +}); + electron.app.on('ready', () => { // No menu bar