Browse Source

Merge pull request #75 from pbca26/master

quit app from dock/bottom bar app menu
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
e6e7d7fe08
  1. 36
      main.js

36
main.js

@ -180,6 +180,8 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) {
let mainWindow; let mainWindow;
let loadingWindow; let loadingWindow;
let willQuitApp = false;
let closeAppAfterLoading = false;
function createLoadingWindow() { function createLoadingWindow() {
mainWindow = null; mainWindow = null;
@ -207,6 +209,20 @@ function createLoadingWindow() {
loadingWindow = null; 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 //ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms
/*if (os.platform() === 'win32') { /*if (os.platform() === 'win32') {
process.chdir(iguanaDir); process.chdir(iguanaDir);
@ -240,6 +256,12 @@ function createWindow (status) {
icon: iguanaIcon icon: iguanaIcon
}); });
if (closeAppAfterLoading) {
mainWindow = null;
loadingWindow = null;
pm2Exit();
}
const staticMenu = Menu.buildFromTemplate([ //if static const staticMenu = Menu.buildFromTemplate([ //if static
{ role: 'copy' }, { role: 'copy' },
{ type: 'separator' }, { type: 'separator' },
@ -277,8 +299,7 @@ function createWindow (status) {
// DEVTOOLS - only for dev purposes - ca333 // DEVTOOLS - only for dev purposes - ca333
//mainWindow.webContents.openDevTools() //mainWindow.webContents.openDevTools()
// if window closed we kill iguana proc function pm2Exit() {
mainWindow.on('closed', function () {
var ConnectToPm2 = function() { var ConnectToPm2 = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('Closing Main Window...'); console.log('Closing Main Window...');
@ -346,6 +367,11 @@ function createWindow (status) {
}) })
.then(HideMainWindow) .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. //Emitted before the application starts closing its windows.
//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. //Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function (event) { app.on('before-quit', function (event) {
console.log('before-quit');
if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced
//loading window is still open //loading window is still open
if (os.platform() === 'darwin') {
let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.<br/>Please wait while all daemons are closed...')`;
loadingWindow.webContents.executeJavaScript(code);
closeAppAfterLoading = true;
}
console.log('before-quit prevented'); console.log('before-quit prevented');
event.preventDefault(); event.preventDefault();
} }

Loading…
Cancel
Save