Skip to content

Commit

Permalink
Merge pull request #1360 from emlys/bugfix/1258
Browse files Browse the repository at this point in the history
Close UG windows when main app window is closed
  • Loading branch information
davemfish authored Aug 9, 2023
2 parents 7843942 + 56286ef commit f2af890
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ Unreleased Changes
* The workbench app is now distributed with a valid code signature
(`#727 <https://github.com/natcap/invest/issues/727>`_)
* Changing the language setting will now cause the app to relaunch
(`#1168 <https://github.com/natcap/invest/issues/1168>`_),
(`#1168 <https://github.com/natcap/invest/issues/1168>`_)
* Closing the main window will now close any user's guide windows that are
open. Fixed a bug where the app could not be reopened after closing.
(`#1258 <https://github.com/natcap/invest/issues/1258>`_)
* Forest Carbon
* The biophysical table is now case-insensitive.
* HRA
Expand Down
20 changes: 13 additions & 7 deletions workbench/src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if (!process.env.PORT) {
let mainWindow;
let splashScreen;
let flaskSubprocess;
let forceQuit = false;

export function destroyWindow() {
mainWindow = null;
Expand Down Expand Up @@ -128,6 +129,16 @@ export const createWindow = async () => {
logger.error(details);
});

mainWindow.on('close', (event) => {
// 'close' is triggered by the red traffic light button on mac
// override this behavior and just minimize,
// unless we're actually quitting the app
if (process.platform === 'darwin' & !forceQuit) {
event.preventDefault();
mainWindow.minimize()
}
});

mainWindow.on('closed', () => {
mainWindow = null;
});
Expand Down Expand Up @@ -179,17 +190,12 @@ export function main() {
createWindow();
}
});
app.on('window-all-closed', async () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});

let shuttingDown = false;
app.on('before-quit', async (event) => {
// prevent quitting until after we're done with cleanup,
// then programatically quit
forceQuit = true;
if (shuttingDown) { return; }
event.preventDefault();
shuttingDown = true;
Expand Down
1 change: 1 addition & 0 deletions workbench/src/main/setupOpenLocalHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function setupOpenLocalHtml(parentWindow, isDevMode) {
ipcMainChannels.OPEN_LOCAL_HTML, (event, url) => {
const [width, height] = parentWindow.getSize();
const child = new BrowserWindow({
parent: parentWindow,
width: width > 1000 ? 1000 : width, // UG content is never wider
height: height,
frame: true,
Expand Down

0 comments on commit f2af890

Please sign in to comment.