1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

fix: prevent multiple app instances

This commit is contained in:
2020-09-15 14:44:29 +02:00
parent 10b426b90b
commit 12fbe8c1a0

View File

@ -6,6 +6,8 @@ import { format as formatUrl } from 'url';
import ipcHandlers from './ipc-handlers'; import ipcHandlers from './ipc-handlers';
const isDevelopment = process.env.NODE_ENV !== 'production'; const isDevelopment = process.env.NODE_ENV !== 'production';
const gotTheLock = app.requestSingleInstanceLock();
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'; process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
// global reference to mainWindow (necessary to prevent window from being garbage collected) // global reference to mainWindow (necessary to prevent window from being garbage collected)
@ -67,23 +69,27 @@ async function createMainWindow () {
return window; return window;
}; };
// Initialize ipcHandlers if (!gotTheLock)
ipcHandlers(); app.quit();
else {
// Initialize ipcHandlers
ipcHandlers();
// quit application when all windows are closed // quit application when all windows are closed
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits // on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') if (process.platform !== 'darwin')
app.quit(); app.quit();
}); });
app.on('activate', () => { app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed // on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) if (mainWindow === null)
mainWindow = createMainWindow();
});
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow(); mainWindow = createMainWindow();
}); });
}
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
});