hot-reload: implememnt auto session/state backup on reload and display error stack in a popup

This commit is contained in:
jean-emmanuel 2018-10-19 21:25:00 +02:00
parent 6f6e1396e4
commit 537dd44795
5 changed files with 109 additions and 52 deletions

View file

@ -4,7 +4,8 @@ var utils = require('../ui/utils'),
widgetManager = require('../managers/widgets'),
state = require('../managers/state'),
editor = require('../editor/'),
locales = require('../locales')
locales = require('../locales'),
ipc = require('./')
module.exports = {
@ -81,11 +82,61 @@ module.exports = {
if (root) root.reCreateWidget()
},100)
GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue('--grid-width')
},
readOnly: function(){
READ_ONLY = true
},
reload: function(){
var id = Math.random(),
search = location.search,
query = 'backupId=' + id
// disable editor's warning
window.onbeforeunload = null
if (!session.session.length) {
window.location.href = window.location.href
return
}
try {
// store session & state backup
ipc.send('storeBackup', {
backupId: id,
session: session.session,
state: state.get()
})
// reload page and hold backup id
if (search) {
search = search.replace(/backupId=[^&]*/, 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)
})
}
}

View file

@ -18,7 +18,8 @@ document.addEventListener('DOMContentLoaded', function(event) {
ipc.init()
require('./app/ui/init')
ipc.send('ready')
ipc.send('ready', {backupId: ARGV.backupId})
}, 100)