Skip to content

Commit 3d45676

Browse files
committed
Prevent multiple instances of the app
1 parent d8e8ace commit 3d45676

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ var al = new AudioLibrary(libraryPersist.store)
3535
module.exports = state
3636
module.exports.al = al
3737

38+
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
39+
// https://github.com/electron/electron/blob/v0.36.10/docs/api/app.md#appmakesingleinstancecallback
40+
// Someone tried to run a second instance, we should focus our window.
41+
if (player.win) {
42+
if (player.win.isMinimized()) player.win.restore()
43+
player.win.focus()
44+
} else {
45+
al.recall()
46+
player.init()
47+
}
48+
})
49+
50+
if (shouldQuit) {
51+
app.exit()
52+
}
53+
3854
app.on('ready', function appReady () {
3955
menu.init()
4056
audio.init()
@@ -216,7 +232,7 @@ app.on('ready', function appReady () {
216232
autoUpdater.checkForUpdatesAndNotify()
217233
}, 500)
218234

219-
if (process.platform !== 'darwin') {
235+
if (process.platform !== 'darwin') { // TODO System tray on windows (maybe linux)
220236
// since window-all-closed doesn't fire with our hidden audio process
221237
player.win.once('closed', () => {
222238
app.quit()

0 commit comments

Comments
 (0)