Skip to content

Commit 190c5e2

Browse files
committed
fix(mac): show window on activate when minimized to tray
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent 0a58b5c commit 190c5e2

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/main.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const path = require('node:path')
77
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')
99
const { setupMenu } = require('./app/app.menu.js')
1010
const { setupReleaseNotificationScheduler } = require('./app/githubReleaseNotification.service.js')
1111
const { enableWebRequestInterceptor, disableWebRequestInterceptor } = require('./app/webRequestInterceptor.js')
@@ -328,21 +328,33 @@ app.whenReady().then(async () => {
328328

329329
ipcMain.on('app:downloadURL', (event, url, filename) => triggerDownloadUrl(mainWindow, url, filename))
330330

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
333332
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.
335340
mainWindow = createMainWindow()
336341
mainWindow.once('ready-to-show', () => mainWindow.show())
337342
}
338343
})
339344
})
340345

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.
344346
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
347356
}
357+
358+
// All the windows are closed - quit the app
359+
app.quit()
348360
})

0 commit comments

Comments
 (0)