mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-22 22:58:33 +00:00
Fix crash when launching a second instance using option --single-instance (Fixes #664)
This refactors the deprecated call to `app.makeSingleInstance()`. See [electron / app.requestSingleInstanceLock()](https://electronjs.org/docs/all?q=app.requestSingleInstanceLock).
This commit is contained in:
parent
a27bb0fd35
commit
479611ecc4
@ -127,21 +127,41 @@ if (appArgs.crashReporter) {
|
||||
});
|
||||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
||||
createTrayIcon(appArgs, mainWindow);
|
||||
// quit if singleInstance mode and there's already another instance running
|
||||
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (!mainWindow.isVisible()) {
|
||||
// try
|
||||
mainWindow.show();
|
||||
}
|
||||
if (mainWindow.isMinimized()) {
|
||||
// minimized
|
||||
mainWindow.restore();
|
||||
}
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Register global shortcuts
|
||||
if (appArgs.globalShortcuts) {
|
||||
appArgs.globalShortcuts.forEach((shortcut) => {
|
||||
globalShortcut.register(shortcut.key, () => {
|
||||
shortcut.inputEvents.forEach((inputEvent) => {
|
||||
mainWindow.webContents.sendInputEvent(inputEvent);
|
||||
app.on('ready', () => {
|
||||
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
||||
createTrayIcon(appArgs, mainWindow);
|
||||
|
||||
// Register global shortcuts
|
||||
if (appArgs.globalShortcuts) {
|
||||
appArgs.globalShortcuts.forEach((shortcut) => {
|
||||
globalShortcut.register(shortcut.key, () => {
|
||||
shortcut.inputEvents.forEach((inputEvent) => {
|
||||
mainWindow.webContents.sendInputEvent(inputEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.on('new-window-for-tab', () => {
|
||||
mainWindow.emit('new-tab');
|
||||
@ -160,24 +180,3 @@ app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||
createLoginWindow(callback);
|
||||
}
|
||||
});
|
||||
|
||||
if (appArgs.singleInstance) {
|
||||
const shouldQuit = app.makeSingleInstance(() => {
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (!mainWindow.isVisible()) {
|
||||
// tray
|
||||
mainWindow.show();
|
||||
}
|
||||
if (mainWindow.isMinimized()) {
|
||||
// minimized
|
||||
mainWindow.restore();
|
||||
}
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user