mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-28 04:19:01 +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', () => {
|
// quit if singleInstance mode and there's already another instance running
|
||||||
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
const shouldQuit = appArgs.singleInstance && !app.requestSingleInstanceLock();
|
||||||
createTrayIcon(appArgs, mainWindow);
|
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
|
app.on('ready', () => {
|
||||||
if (appArgs.globalShortcuts) {
|
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
||||||
appArgs.globalShortcuts.forEach((shortcut) => {
|
createTrayIcon(appArgs, mainWindow);
|
||||||
globalShortcut.register(shortcut.key, () => {
|
|
||||||
shortcut.inputEvents.forEach((inputEvent) => {
|
// Register global shortcuts
|
||||||
mainWindow.webContents.sendInputEvent(inputEvent);
|
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', () => {
|
app.on('new-window-for-tab', () => {
|
||||||
mainWindow.emit('new-tab');
|
mainWindow.emit('new-tab');
|
||||||
@ -160,24 +180,3 @@ app.on('login', (event, webContents, request, authInfo, callback) => {
|
|||||||
createLoginWindow(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…
Reference in New Issue
Block a user