Skip to content

Commit c5bfcf1

Browse files
committed
Add makeSingleInstance helper function
1 parent 0725d3d commit c5bfcf1

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

main.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ process.throwDeprecation = true
1414
var mainWindow = null
1515

1616
function initialize () {
17-
var shouldQuit = app.makeSingleInstance(function () {
18-
if (mainWindow) {
19-
if (mainWindow.isMinimized()) mainWindow.restore()
20-
mainWindow.focus()
21-
}
22-
})
23-
17+
var shouldQuit = makeSingleInstance()
2418
if (shouldQuit) {
2519
app.quit()
2620
return
@@ -69,6 +63,22 @@ function initialize () {
6963
})
7064
}
7165

66+
// Make this app a single instance app.
67+
//
68+
// The main window will be restored and focused instead of a second window
69+
// opened when a person attempts to launch a second instance.
70+
//
71+
// Returns true if the current version of the app should quit instead of
72+
// launching.
73+
function makeSingleInstance () {
74+
return app.makeSingleInstance(function () {
75+
if (mainWindow) {
76+
if (mainWindow.isMinimized()) mainWindow.restore()
77+
mainWindow.focus()
78+
}
79+
})
80+
}
81+
7282
// Handle Squirrel on Windows startup events
7383
switch (process.argv[1]) {
7484
case '--squirrel-install':

0 commit comments

Comments
 (0)