Skip to content

Commit 1092cbc

Browse files
authored
fix: tray window closed on first app quit (#660)
1 parent 2c0d0ef commit 1092cbc

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/main/main.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ export const createWindow = async () => {
216216
app.on('window-all-closed', () => {
217217
// Respect the OSX convention of having the application in memory even
218218
// after all windows have been closed
219-
app.quit(); // todo: remove
220219
if (process.platform !== 'darwin') {
220+
onExit();
221221
app.quit();
222222
}
223223
});
@@ -226,29 +226,37 @@ app.on('window-all-closed', () => {
226226
let isFullQuit = false;
227227
export const fullQuit = () => {
228228
isFullQuit = true;
229+
onExit();
229230
app.quit();
230231
};
231232

232233
export const setFullQuitForNextQuit = (_isNextQuitAFullQuit: boolean) => {
233234
isFullQuit = _isNextQuitAFullQuit;
234235
};
235236

236-
// Emitted on app.quit() after all windows have been closed
237-
app.on('will-quit', (e) => {
237+
// app.on('will-quit') is emitted on app.quit() after all windows have been closed
238+
// However, we don't want it to close the tray window! So we catch the quit action and stop
239+
// it before it closes the tray window, and we only close the main window.
240+
241+
app.on('before-quit', (e) => {
238242
// Remove dev env check to test background. This is to prevent
239243
// multiple instances of the app staying open in dev env where we
240244
// regularly quit the app.
241-
app.quit(); // todo: remove
245+
logger.info(`app.on('will-quit'): isFullQuit: ${isFullQuit}`);
242246
if (isFullQuit || process.env.NODE_ENV === 'development') {
243-
console.log('quitting app from background');
244-
app.quit();
247+
// if (isFullQuit) {
248+
logger.info('quitting app from background');
249+
onExit();
250+
// continue with quitting
245251
} else {
246-
console.log('quitting app from foreground');
252+
logger.info('quitting app from foreground');
247253
// This allows NN to run in the background. The purpose is to keep a tray icon updated,
248254
// monitor node's statuses and alert the user when a node is down, and to continuously
249255
// track node usage.
250-
e.preventDefault();
256+
e.preventDefault(); // halts electron's full quitting action
257+
// todo: close windows?
251258
if (process.platform === 'darwin' && app.dock) {
259+
mainWindow?.close(); // close the main window
252260
app.dock.hide(); // app appears "quitted" in the dock
253261
}
254262
}
@@ -269,7 +277,6 @@ const onExit = () => {
269277
onExitNodeManager();
270278
monitor.onExit();
271279
cronJobs.onExit();
272-
app.quit(); // todo: remove
273280
};
274281

275282
// no blocking work

src/main/podman/metricsPolling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ const updateAllNodeMetrics = async () => {
7676
}
7777
nodeStore.updateNode(node);
7878
} catch (err) {
79-
logger.error('Error setting metrics for a node', err);
79+
logger.error('Error setting metrics for a node...');
80+
logger.error(err);
8081
}
8182
} else {
8283
// no containerId for a node

src/main/tray.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ export const initialize = (getAssetPath: (...paths: string[]) => string) => {
441441
// on windows, default is open/show window on click
442442
// on mac, default is open menu on click (no code needed)
443443
// on linux?
444+
logger.info('tray icon clicked');
444445
if (isMac()) {
445446
toggleCustomTrayWindow();
446447
updateCustomTrayMenu();

0 commit comments

Comments
 (0)