Skip to content

Commit 3c0f20f

Browse files
jhdcruzRokt33r
authored andcommitted
Single Instance fix #3241
Fixes single instance depreciation
1 parent 59f8425 commit 3c0f20f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/main-app.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@ const ipc = electron.ipcMain
55
const GhReleases = require('electron-gh-releases')
66
const { isPackaged } = app
77
// electron.crashReporter.start()
8+
const singleInstance = app.requestSingleInstanceLock()
89

910
var ipcServer = null
1011

1112
var mainWindow = null
1213

13-
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
14-
if (mainWindow) {
15-
if (process.platform === 'win32') {
16-
mainWindow.minimize()
17-
mainWindow.restore()
18-
}
19-
mainWindow.focus()
20-
}
21-
return true
22-
})
23-
24-
if (shouldQuit) {
14+
// Single Instance Lock
15+
if (!singleInstance) {
2516
app.quit()
17+
} else {
18+
app.on('second-instance', () => {
19+
// Someone tried to run a second instance, it should focus the existing instance.
20+
if (mainWindow) {
21+
if (!mainWindow.isVisible()) mainWindow.show()
22+
mainWindow.focus()
23+
}
24+
})
2625
}
2726

2827
var isUpdateReady = false

0 commit comments

Comments
 (0)