diff --git a/main.js b/main.js index de98e81..9c8e35a 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,20 @@ 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(); + console.log('lwindow' + loadingWindow); + if (loadingWindow) + 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 +256,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 +299,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 +366,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,8 +393,14 @@ 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 + 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(); }