Skip to content

Commit 548faf0

Browse files
authored
Merge pull request #265 from hypermodules/fix-windows-lifecycle
Fix windows lifecycle
2 parents a2e3c28 + 3d45676 commit 548faf0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 0.5.5 - 2017-11-10
6+
* Fix window (and linux?) lifecycle bug
7+
58
## 0.5.4 - 2017-11-10
69
* Update choo devtools
710
* Remove choo log

main/index.js

Lines changed: 23 additions & 4 deletions
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()
@@ -215,6 +231,13 @@ app.on('ready', function appReady () {
215231
setTimeout(() => {
216232
autoUpdater.checkForUpdatesAndNotify()
217233
}, 500)
234+
235+
if (process.platform !== 'darwin') { // TODO System tray on windows (maybe linux)
236+
// since window-all-closed doesn't fire with our hidden audio process
237+
player.win.once('closed', () => {
238+
app.quit()
239+
})
240+
}
218241
})
219242

220243
autoUpdater.on('error', (err) => {
@@ -249,10 +272,6 @@ autoUpdater.on('update-downloaded', (info) => {
249272
console.log(info)
250273
})
251274

252-
app.on('window-all-closed', function allWindowsClosed () {
253-
if (process.platform !== 'darwin') app.quit()
254-
})
255-
256275
app.on('activate', function activate () {
257276
if (player.win === null) {
258277
al.recall()

0 commit comments

Comments
 (0)