From 9994606330f5f784d424c97ccfe594f55c540fe2 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 28 Mar 2017 11:26:44 +0200 Subject: [PATCH 1/3] quit app from dock/bottom bar app menu --- main.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index de98e81..3890f1d 100644 --- a/main.js +++ b/main.js @@ -180,6 +180,8 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) { let mainWindow; let loadingWindow; +let willQuitApp = false; +let closeAppAfterLoading = false; function createLoadingWindow() { mainWindow = null; @@ -207,6 +209,18 @@ function createLoadingWindow() { loadingWindow = null; }); + loadingWindow.on('close', (e) => { + if (willQuitApp) { + /* the user tried to quit the app */ + loadingWindow = null; + } else { + /* the user only tried to close the window */ + closeAppAfterLoading = true; + e.preventDefault(); + loadingWindow.hide(); + } + }); + //ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms /*if (os.platform() === 'win32') { process.chdir(iguanaDir); @@ -240,6 +254,12 @@ function createWindow (status) { icon: iguanaIcon }); + if (closeAppAfterLoading) { + mainWindow = null; + loadingWindow = null; + pm2Exit(); + } + const staticMenu = Menu.buildFromTemplate([ //if static { role: 'copy' }, { type: 'separator' }, @@ -277,8 +297,7 @@ function createWindow (status) { // DEVTOOLS - only for dev purposes - ca333 //mainWindow.webContents.openDevTools() - // if window closed we kill iguana proc - mainWindow.on('closed', function () { + function pm2Exit() { var ConnectToPm2 = function() { return new Promise(function(resolve, reject) { console.log('Closing Main Window...'); @@ -345,7 +364,12 @@ function createWindow (status) { return KillPm2(); }) .then(HideMainWindow) - .then(QuitApp); + .then(QuitApp); + } + + // if window closed we kill iguana proc + mainWindow.on('closed', function () { + pm2Exit(); }); } } @@ -367,6 +391,7 @@ 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) { + console.log('before-quit'); if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced //loading window is still open console.log('before-quit prevented'); From 12cc994460d8df85ab9d63dbce51020ca008f772 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 28 Mar 2017 12:56:29 +0200 Subject: [PATCH 2/3] added missing loadingWindow check in defered app quit --- main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 3890f1d..b272240 100644 --- a/main.js +++ b/main.js @@ -217,7 +217,8 @@ function createLoadingWindow() { /* the user only tried to close the window */ closeAppAfterLoading = true; e.preventDefault(); - loadingWindow.hide(); + if (loadingWindow) + loadingWindow.hide(); } }); From 3cddd53ca80f8a0aef64470caa9c4ea6e5bb29fc Mon Sep 17 00:00:00 2001 From: pbca26 Date: Tue, 28 Mar 2017 19:21:10 +0200 Subject: [PATCH 3/3] added condition to trigger defered quit on osx --- main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.js b/main.js index b272240..9c8e35a 100644 --- a/main.js +++ b/main.js @@ -217,6 +217,7 @@ function createLoadingWindow() { /* the user only tried to close the window */ closeAppAfterLoading = true; e.preventDefault(); + console.log('lwindow' + loadingWindow); if (loadingWindow) loadingWindow.hide(); } @@ -395,6 +396,11 @@ app.on('before-quit', function (event) { console.log('before-quit'); if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced //loading window is still open + if (os.platform() === 'darwin') { + let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.
Please wait while all daemons are closed...')`; + loadingWindow.webContents.executeJavaScript(code); + closeAppAfterLoading = true; + } console.log('before-quit prevented'); event.preventDefault(); }