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

View file

@ -1,6 +1,6 @@
var utils = require('../ui/utils'),
osc = require('../osc'),
session = require('../managers/session'),
session = require('../managers/session/'),
widgetManager = require('../managers/widgets'),
state = require('../managers/state'),
editor = require('../editor/'),
@ -11,7 +11,8 @@ var utils = require('../ui/utils'),
notifications = require('../ui/notifications'),
{TRAVERSING_SAMEWIDGET} = require('../events/utils'),
raw = require('nanohtml/raw'),
ipc = require('./')
ipc = require('./'),
backup = require('../backup')
module.exports = {
@ -96,75 +97,9 @@ module.exports = {
reload: function(){
var id = Math.random(),
search = location.search,
query = 'backupId=' + id
// disable editor's warning
backup.save()
window.onbeforeunload = null
if (!session.session) {
window.location.href = window.location.href
return
}
try {
// store session & state backup
ipc.send('storeBackup', {
backupId: id,
session: session.session || {},
sessionPath: session.sessionPath,
state: state.get(),
history: editor.history,
historyState: editor.historyState,
editorEnabled: editor.enabled,
})
// reload page and hold backup id
if (search) {
if (search.includes('backupId=')) {
search = search.replace(/backupId=[^&]*/, query)
} else {
search += '&' + query
}
} else {
search += '?' + query
}
window.location.search = search
} catch(e) {
window.location.href = window.location.href
}
},
loadBackup: function(data) {
session.load(data.session, ()=>{
state.set(data.state, false)
editor.historySession = deepCopy(data.session)
editor.history = data.history
editor.historyState = data.historyState
if (data.editorEnabled) editor.enable()
if (data.traversing === TRAVERSING_SAMEWIDGET) {
DOM.get('.traversingSmart')[0].click()
} else if (data.traversing) {
DOM.get('.traversingEnable')[0].click()
}
ipc.send('sessionSetPath', {path: data.sessionPath})
session.setSessionPath(data.sessionPath)
ipc.send('deleteBackup', data.backupId)
})
window.location.href = window.location.href
},