|
5 | 5 |
|
6 | 6 | const path = require('node:path') |
7 | 7 | const { spawn } = require('node:child_process') |
8 | | -const { app, dialog, BrowserWindow, ipcMain, desktopCapturer, systemPreferences, shell } = require('electron') |
| 8 | +const { app, dialog, ipcMain, desktopCapturer, systemPreferences, shell } = require('electron') |
9 | 9 | const { setupMenu } = require('./app/app.menu.js') |
10 | 10 | const { setupReleaseNotificationScheduler } = require('./app/githubReleaseNotification.service.js') |
11 | 11 | const { enableWebRequestInterceptor, disableWebRequestInterceptor } = require('./app/webRequestInterceptor.js') |
@@ -328,21 +328,33 @@ app.whenReady().then(async () => { |
328 | 328 |
|
329 | 329 | ipcMain.on('app:downloadURL', (event, url, filename) => triggerDownloadUrl(mainWindow, url, filename)) |
330 | 330 |
|
331 | | - // On OS X it's common to re-create a window in the app when the |
332 | | - // dock icon is clicked and there are no other windows open. |
| 331 | + // Click on the dock icon on macOS |
333 | 332 | app.on('activate', () => { |
334 | | - if (BrowserWindow.getAllWindows().length === 0) { |
| 333 | + if (mainWindow && !mainWindow.isDestroyed()) { |
| 334 | + // Show the main window if it exists but hidden (not closed), e.g., minimized to the system tray |
| 335 | + mainWindow.show() |
| 336 | + } else { |
| 337 | + // On macOS, it is common to re-create a window in the app when the |
| 338 | + // dock icon is clicked and there are no other windows open. |
| 339 | + // See window-all-closed event handler. |
335 | 340 | mainWindow = createMainWindow() |
336 | 341 | mainWindow.once('ready-to-show', () => mainWindow.show()) |
337 | 342 | } |
338 | 343 | }) |
339 | 344 | }) |
340 | 345 |
|
341 | | -// Quit when all windows are closed, except on macOS. There, it's common |
342 | | -// for applications and their menu bar to stay active until the user quits |
343 | | -// explicitly with Cmd + Q. |
344 | 346 | app.on('window-all-closed', () => { |
345 | | - if (process.platform !== 'darwin' && !isInWindowRelaunch) { |
346 | | - app.quit() |
| 347 | + // Recreating a window - keep app running |
| 348 | + if (isInWindowRelaunch) { |
| 349 | + return |
| 350 | + } |
| 351 | + |
| 352 | + // On macOS, it is common for applications and their menu bar to stay active even without windows |
| 353 | + // until the user quits explicitly with Cmd + Q or Quit from the menu. |
| 354 | + if (isMac()) { |
| 355 | + return |
347 | 356 | } |
| 357 | + |
| 358 | + // All the windows are closed - quit the app |
| 359 | + app.quit() |
348 | 360 | }) |
0 commit comments