diff --git a/main/ipc.js b/main/ipc.js index 81e51b2c..bd3b090e 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -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) + } +} diff --git a/renderer/index.js b/renderer/index.js index 2e8c43be..1c633a06 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -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()