session: implement session converter; add some meta data

dev: handle hot reload data with localStorage
This commit is contained in:
bordun 2020-03-26 12:29:06 +01:00
parent 60812ed042
commit 0312959145
12 changed files with 243 additions and 127 deletions

58
src/client/backup.js Normal file
View file

@ -0,0 +1,58 @@
var localBackup = localStorage.getItem('osc.backup')
module.exports = {
exists: localBackup !== null,
save: ()=>{
var session = require('./managers/session/'),
state = require('./managers/state'),
editor = require('./editor/')
if (session.session) {
localStorage.setItem('osc.backup', JSON.stringify({
session: session.session.data,
sessionPath: session.sessionPath,
state: state.get(),
history: editor.history,
historyState: editor.historyState,
editorEnabled: editor.enabled
}))
}
},
load: ()=>{
var session = require('./managers/session/'),
state = require('./managers/state'),
editor = require('./editor/'),
ipc = require('./ipc/')
if (localBackup) {
var data = JSON.parse(localBackup)
localStorage.removeItem('osc.backup')
session.load(data.session, ()=>{
state.set(data.state, false)
editor.clearHistory()
editor.history = data.history
editor.historyState = data.historyState
if (data.editorEnabled) editor.enable()
ipc.send('sessionSetPath', {path: data.sessionPath})
session.setSessionPath(data.sessionPath)
})
}
}
}