Skip to content

Commit

Permalink
fix: tray window closed on first app quit (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgresham authored Sep 16, 2024
1 parent 2c0d0ef commit 1092cbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export const createWindow = async () => {
app.on('window-all-closed', () => {
// Respect the OSX convention of having the application in memory even
// after all windows have been closed
app.quit(); // todo: remove
if (process.platform !== 'darwin') {
onExit();
app.quit();
}
});
Expand All @@ -226,29 +226,37 @@ app.on('window-all-closed', () => {
let isFullQuit = false;
export const fullQuit = () => {
isFullQuit = true;
onExit();
app.quit();
};

export const setFullQuitForNextQuit = (_isNextQuitAFullQuit: boolean) => {
isFullQuit = _isNextQuitAFullQuit;
};

// Emitted on app.quit() after all windows have been closed
app.on('will-quit', (e) => {
// app.on('will-quit') is emitted on app.quit() after all windows have been closed
// However, we don't want it to close the tray window! So we catch the quit action and stop
// it before it closes the tray window, and we only close the main window.

app.on('before-quit', (e) => {
// Remove dev env check to test background. This is to prevent
// multiple instances of the app staying open in dev env where we
// regularly quit the app.
app.quit(); // todo: remove
logger.info(`app.on('will-quit'): isFullQuit: ${isFullQuit}`);
if (isFullQuit || process.env.NODE_ENV === 'development') {
console.log('quitting app from background');
app.quit();
// if (isFullQuit) {
logger.info('quitting app from background');
onExit();
// continue with quitting
} else {
console.log('quitting app from foreground');
logger.info('quitting app from foreground');
// This allows NN to run in the background. The purpose is to keep a tray icon updated,
// monitor node's statuses and alert the user when a node is down, and to continuously
// track node usage.
e.preventDefault();
e.preventDefault(); // halts electron's full quitting action
// todo: close windows?
if (process.platform === 'darwin' && app.dock) {
mainWindow?.close(); // close the main window
app.dock.hide(); // app appears "quitted" in the dock
}
}
Expand All @@ -269,7 +277,6 @@ const onExit = () => {
onExitNodeManager();
monitor.onExit();
cronJobs.onExit();
app.quit(); // todo: remove
};

// no blocking work
Expand Down
3 changes: 2 additions & 1 deletion src/main/podman/metricsPolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const updateAllNodeMetrics = async () => {
}
nodeStore.updateNode(node);
} catch (err) {
logger.error('Error setting metrics for a node', err);
logger.error('Error setting metrics for a node...');
logger.error(err);
}
} else {
// no containerId for a node
Expand Down
1 change: 1 addition & 0 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export const initialize = (getAssetPath: (...paths: string[]) => string) => {
// on windows, default is open/show window on click
// on mac, default is open menu on click (no code needed)
// on linux?
logger.info('tray icon clicked');
if (isMac()) {
toggleCustomTrayWindow();
updateCustomTrayMenu();
Expand Down

0 comments on commit 1092cbc

Please sign in to comment.