From 84e566206803a7ec46453197514f7a530b123e9e Mon Sep 17 00:00:00 2001 From: meriadec Date: Thu, 5 Jul 2018 11:45:09 +0200 Subject: [PATCH 1/2] Quit app if not main instance --- src/main/app.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/app.js b/src/main/app.js index cab281b3..50a79bd4 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -17,6 +17,17 @@ import { terminateAllTheThings } from './terminator' // necessary to prevent win from being garbage collected let mainWindow = null +const isSecondInstance = app.makeSingleInstance(() => { + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + } +}) + +if (isSecondInstance) { + app.quit() +} + export const getMainWindow = () => mainWindow // TODO put back OSX close behavior From 5dff2cd84cc5c8ce3e0ab88228e59ecca2e111b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 5 Jul 2018 12:00:57 +0200 Subject: [PATCH 2/2] Remove MacOSX previous behavior until we refactor it properly --- src/main/app.js | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/main/app.js b/src/main/app.js index 50a79bd4..412a323b 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -30,9 +30,6 @@ if (isSecondInstance) { export const getMainWindow = () => mainWindow -// TODO put back OSX close behavior -// let forceClose = false - const { UPGRADE_EXTENSIONS, ELECTRON_WEBPACK_WDS_PORT, DEV_TOOLS, DEV_TOOLS_MODE } = process.env const devTools = __DEV__ || DEV_TOOLS @@ -46,17 +43,6 @@ const getWindowPosition = (height, width, display = screen.getPrimaryDisplay()) } } -// TODO put back OSX close behavior -// const handleCloseWindow = w => e => { -// if (!forceClose) { -// e.preventDefault() -// w.webContents.send('lock') -// if (w !== null) { -// w.hide() -// } -// } -// } - const getDefaultUrl = () => __DEV__ ? `http://localhost:${ELECTRON_WEBPACK_WDS_PORT || ''}` : `file://${__dirname}/index.html` @@ -127,8 +113,6 @@ function createMainWindow() { window.loadURL(url) - // TODO put back OSX close behavior - // window.on('close', handleCloseWindow(window)) window.on('close', terminateAllTheThings) window.on('ready-to-show', () => { @@ -148,25 +132,12 @@ function createMainWindow() { return window } -// TODO put back OSX close behavior -// app.on('before-quit', () => { -// forceClose = true -// }) - app.on('window-all-closed', () => { - // On macOS it is common for applications to stay open - // until the user explicitly quits - if (process.platform !== 'darwin') { - app.quit() - } + app.quit() }) app.on('activate', () => { - // On macOS it is common to re-create a window - // even after all windows have been closed - if (mainWindow === null) { - mainWindow = createMainWindow() - } else { + if (mainWindow) { mainWindow.show() } })