From 29e3495e520e3bec99c669e048f1e5ea941d9756 Mon Sep 17 00:00:00 2001 From: ca333 Date: Wed, 15 Feb 2017 07:31:53 +0100 Subject: [PATCH] prevent bad exit --- gui/init.js | 4 ++-- gui/loading.js | 2 +- main.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gui/init.js b/gui/init.js index a36bbaa..7a2571a 100644 --- a/gui/init.js +++ b/gui/init.js @@ -40,6 +40,6 @@ $(document).ready(function() { sartcheck(); //setTimeout(function(){ window.close(); }, 15000); } else { - window.close(); + window.hide(); } -}); \ No newline at end of file +}); diff --git a/gui/loading.js b/gui/loading.js index ab5fefc..e8b5b48 100644 --- a/gui/loading.js +++ b/gui/loading.js @@ -130,7 +130,7 @@ function EDEX_DEXgetinfoAll() { $('#loading_sub_status_output_text').text('Output: Connected') } if ( tmp_index == 10 ) { - window.close(); + window.hide(); } }).fail(function(xhr, textStatus, error) { // handle request failures diff --git a/main.js b/main.js index e46f844..45d98f1 100644 --- a/main.js +++ b/main.js @@ -144,7 +144,7 @@ function createLoadingWindow() { //loadingWindow.webContents.openDevTools() // if window closed we kill iguana proc - loadingWindow.on('closed', function () { + loadingWindow.on('hide', function () { // our app does not have multiwindow - so we dereference the window object instead of // putting them into an window_arr loadingWindow = null; @@ -280,6 +280,35 @@ app.on('window-all-closed', function () { }*/ }) +//Emitted before the application starts closing its windows. +//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. +app.on('before-quit', function (event) { + if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced + //loading window is still open + console.log("before-quit prevented"); + event.preventDefault(); + } +}) + +//Emitted when all windows have been closed and the application will quit. +//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. +app.on('will-quit', function (event) { + if (mainWindow === null && loadingWindow != null) { + //loading window is still open + console.log("will-quit while loading window active"); + event.preventDefault(); + } +}) + +//Emitted when the application is quitting. +//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. +app.on('quit', function (event) { + if (mainWindow === null && loadingWindow != null) { + console.log("quit while loading window active"); + event.preventDefault(); + } +}) + app.on('activate', function () { if (mainWindow === null) { //createWindow('open');