Refactor main.js: media and update controllers

This commit is contained in:
DC
2016-06-23 02:43:30 -07:00
parent bac43509d2
commit c3a27dbebe
4 changed files with 158 additions and 85 deletions

View File

@@ -1,7 +1,8 @@
module.exports = {
getDefaultPlayState,
load,
save
save,
saveThrottled
}
var appConfig = require('application-config')('WebTorrent')
@@ -180,6 +181,7 @@ function load (cb) {
// Write state.saved to the JSON state file
function save (state, cb) {
console.log('Saving state to ' + appConfig.filePath)
delete state.saveStateTimeout
var electron = require('electron')
@@ -210,3 +212,12 @@ function save (state, cb) {
electron.ipcRenderer.send('savedState')
})
}
// Write, but no more than once a second
function saveThrottled (state) {
if (state.saveStateTimeout) return
state.saveStateTimeout = setTimeout(function () {
if (!state.saveStateTimeout) return
save(state)
}, 1000)
}