Merge pull request #142 from feross/fix-141

fix #141
This commit is contained in:
Nate Goldman
2016-03-14 11:40:42 -07:00
2 changed files with 20 additions and 19 deletions

View File

@@ -12,7 +12,7 @@ var menu = require('./menu')
var windows = require('./windows')
// has to be a number, not a boolean, and undefined throws an error
var powerSaveBlocked = 0
var powerSaveBlockID = 0
function init () {
ipcMain.on('showOpenTorrentFile', function (e) {
@@ -43,24 +43,12 @@ function init () {
windows.main.setTitle(title)
})
ipcMain.on('blockPowerSave', blockPowerSave)
ipcMain.on('unblockPowerSave', unblockPowerSave)
ipcMain.on('log', function (e, message) {
console.log(message)
})
ipcMain.on('playing-video', function (e) {
powerSaveBlocked = powerSaveBlocker.start('prevent-display-sleep')
})
ipcMain.on('paused-video', function (e) {
if (powerSaveBlocker.isStarted(powerSaveBlocked)) {
powerSaveBlocker.stop(powerSaveBlocked)
}
})
ipcMain.on('openItem', function (e, path) {
console.log('opening file or folder: ' + path)
electron.shell.openItem(path)
})
}
function setBounds (bounds) {
@@ -90,3 +78,15 @@ function setProgress (progress) {
windows.main.setProgressBar(progress)
}
}
function blockPowerSave () {
powerSaveBlockID = powerSaveBlocker.start('prevent-display-sleep')
debug('blockPowerSave %d', powerSaveBlockID)
}
function unblockPowerSave () {
if (powerSaveBlocker.isStarted(powerSaveBlockID)) {
powerSaveBlocker.stop(powerSaveBlockID)
debug('unblockPowerSave %d', powerSaveBlockID)
}
}

View File

@@ -79,8 +79,6 @@ function init () {
updateClientProgress()
}, 1000)
// All state lives in state.js. `state.saved` is read from and written to a
// file. All other state is ephemeral.
window.addEventListener('beforeunload', saveState)
// listen for messages from the main process
@@ -201,6 +199,7 @@ function dispatch (action, ...args) {
if (action === 'back') {
// TODO
// window.history.back()
ipcRenderer.send('unblockPowerSave')
closePlayer()
}
if (action === 'forward') {
@@ -215,10 +214,11 @@ function dispatch (action, ...args) {
update()
}
if (action === 'videoPlaying') {
ipcRenderer.send('playing-video')
ipcRenderer.send('blockPowerSave')
}
if (action === 'videoPaused') {
ipcRenderer.send('paused-video')
ipcRenderer.send('unblockPowerSave')
}
if (action === 'playPause') {
state.video.isPaused = !state.video.isPaused
@@ -564,6 +564,7 @@ function closePlayer () {
if (state.window.isFullScreen) {
dispatch('toggleFullScreen', false)
}
restoreBounds()
stopServer()
update()