Skip to content

Commit 3a52680

Browse files
Bugfix #258: electron.manifest.json - singleInstance not working
1 parent 06f4303 commit 3a52680

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ElectronNET.Host/main.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ const imageSize = require('image-size');
77
let io, server, browserWindows, ipc, apiProcess, loadURL;
88
let appApi, menu, dialogApi, notification, tray, webContents;
99
let globalShortcut, shellApi, screen, clipboard, autoUpdater;
10-
let splashScreen, mainWindowId, hostHook;
10+
let splashScreen, hostHook;
1111

1212
const currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
1313
const manifestJsonFilePath = path.join(currentBinPath, 'electron.manifest.json');
1414
const manifestJsonFile = require(manifestJsonFilePath);
1515
if (manifestJsonFile.singleInstance) {
16-
const shouldQuit = app.requestSingleInstanceLock();
17-
app.on('second-instance', (commandLine, workingDirectory) => {
18-
mainWindowId && BrowserWindow.fromId(mainWindowId) && BrowserWindow.fromId(mainWindowId).show();
16+
const mainInstance = app.requestSingleInstanceLock();
17+
app.on('second-instance', () => {
18+
const windows = BrowserWindow.getAllWindows();
19+
if (windows.length) {
20+
if (windows[0].isMinimized()) {
21+
windows[0].restore();
22+
}
23+
windows[0].focus();
24+
}
1925
});
2026

21-
if (shouldQuit) {
27+
if (!mainInstance) {
2228
app.quit();
2329
}
2430
}
@@ -37,9 +43,9 @@ app.on('ready', () => {
3743
});
3844

3945
function isSplashScreenEnabled() {
40-
if(manifestJsonFile.hasOwnProperty('splashscreen')) {
41-
if(manifestJsonFile.splashscreen.hasOwnProperty('imageFile')) {
42-
return Boolean(manifestJsonFile.splashscreen.imageFile);
46+
if (manifestJsonFile.hasOwnProperty('splashscreen')) {
47+
if (manifestJsonFile.splashscreen.hasOwnProperty('imageFile')) {
48+
return Boolean(manifestJsonFile.splashscreen.imageFile);
4349
}
4450
}
4551

0 commit comments

Comments
 (0)