Exit media when user closes window (#348)
This commit is contained in:
@@ -106,7 +106,7 @@ function createMainWindow () {
|
|||||||
win.on('close', function (e) {
|
win.on('close', function (e) {
|
||||||
if (!electron.app.isQuitting) {
|
if (!electron.app.isQuitting) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
win.send('dispatch', 'pause')
|
win.send('dispatch', 'backToList')
|
||||||
win.hide()
|
win.hide()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -218,6 +218,16 @@ function dispatch (action, ...args) {
|
|||||||
if (action === 'setDimensions') {
|
if (action === 'setDimensions') {
|
||||||
setDimensions(args[0] /* dimensions */)
|
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') {
|
if (action === 'back') {
|
||||||
state.location.back()
|
state.location.back()
|
||||||
}
|
}
|
||||||
@@ -240,13 +250,6 @@ function dispatch (action, ...args) {
|
|||||||
}
|
}
|
||||||
if (action === 'pause') {
|
if (action === 'pause') {
|
||||||
playPause(true)
|
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') {
|
if (action === 'playbackJump') {
|
||||||
jumpToTime(args[0] /* seconds */)
|
jumpToTime(args[0] /* seconds */)
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ LocationHistory.prototype.back = function () {
|
|||||||
var page = this._history.pop()
|
var page = this._history.pop()
|
||||||
|
|
||||||
if (page.onbeforeunload) {
|
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(() => {
|
page.onbeforeunload(() => {
|
||||||
this._forward.push(page)
|
this._forward.push(page)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user