Merge pull request #133 from Flet/pause-on-hide-again

ensure video is paused before hiding window
This commit is contained in:
Feross Aboukhadijeh
2016-03-10 23:41:04 -08:00
3 changed files with 16 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ var windows = module.exports = {
var config = require('../config') var config = require('../config')
var debug = require('debug')('webtorrent-app:windows') var debug = require('debug')('webtorrent-app:windows')
var electron = require('electron') var electron = require('electron')
var ipcMain = electron.ipcMain
var menu = require('./menu') var menu = require('./menu')
var app = electron.app var app = electron.app
@@ -44,10 +45,14 @@ function createMainWindow () {
win.on('close', function (e) { win.on('close', function (e) {
if (process.platform === 'darwin' && !app.isQuitting) { if (process.platform === 'darwin' && !app.isQuitting) {
e.preventDefault() e.preventDefault()
// sendSync() ensures that video will pause before window is hidden, at which point // When the window is hidden, the update() loop (which uses
// the update() loop (which uses requestAnimationFrame) ceases to run // requestAnimationFrame) ceases to run. We need to make sure
win.sendSync('dispatch', 'pause') // the video pauses before hiding or it will continue to play.
win.hide()
win.send('dispatch', 'pause')
ipcMain.once('paused-video', function (e) {
win.hide()
})
} }
}) })

View File

@@ -197,9 +197,15 @@ function dispatch (action, ...args) {
// window.history.forward() // window.history.forward()
} }
if (action === 'pause') { if (action === 'pause') {
if (state.url !== 'player' || state.video.isPaused) {
ipcRenderer.send('paused-video')
}
state.video.isPaused = true state.video.isPaused = true
update() update()
} }
if (action === 'videoPaused') {
ipcRenderer.send('paused-video')
}
if (action === 'playPause') { if (action === 'playPause') {
state.video.isPaused = !state.video.isPaused state.video.isPaused = !state.video.isPaused
update() update()

View File

@@ -36,6 +36,7 @@ function Player (state, dispatch) {
ondblclick=${() => dispatch('toggleFullScreen')} ondblclick=${() => dispatch('toggleFullScreen')}
onloadedmetadata=${onLoadedMetadata} onloadedmetadata=${onLoadedMetadata}
onended=${onEnded} onended=${onEnded}
onpause=${() => dispatch('videoPaused')}
autoplay> autoplay>
</video> </video>
</div> </div>