Exit media when user closes window (#348)

This commit is contained in:
DC
2016-04-10 16:46:34 -07:00
committed by Feross Aboukhadijeh
parent f8095fcdbf
commit 69460db294
3 changed files with 14 additions and 8 deletions

View File

@@ -106,7 +106,7 @@ function createMainWindow () {
win.on('close', function (e) {
if (!electron.app.isQuitting) {
e.preventDefault()
win.send('dispatch', 'pause')
win.send('dispatch', 'backToList')
win.hide()
}
})

View File

@@ -218,6 +218,16 @@ function dispatch (action, ...args) {
if (action === 'setDimensions') {
setDimensions(args[0] /* dimensions */)
}
if (action === 'backToList') {
while (state.location.hasBack()) state.location.back()
// Work around virtual-dom issue: it doesn't expose its redraw function,
// and only redraws on requestAnimationFrame(). That means when the user
// closes the window (hide window / minimize to tray) and we want to pause
// the video, we update the vdom but it keeps playing until you reopen!
var mediaTag = document.querySelector('video,audio')
if (mediaTag) mediaTag.pause()
}
if (action === 'back') {
state.location.back()
}
@@ -240,13 +250,6 @@ function dispatch (action, ...args) {
}
if (action === 'pause') {
playPause(true)
// Work around virtual-dom issue: it doesn't expose its redraw function,
// and only redraws on requestAnimationFrame(). That means when the user
// closes the window (hide window / minimize to tray) and we want to pause
// the video, we update the vdom but it keeps playing until you reopen!
var mediaTag = document.querySelector('video,audio')
if (mediaTag) mediaTag.pause()
}
if (action === 'playbackJump') {
jumpToTime(args[0] /* seconds */)

View File

@@ -34,6 +34,9 @@ LocationHistory.prototype.back = function () {
var page = this._history.pop()
if (page.onbeforeunload) {
// TODO: this is buggy. If the user clicks back twice, then those pages
// may end up in _forward in the wrong order depending on which onbeforeunload
// call finishes first.
page.onbeforeunload(() => {
this._forward.push(page)
})