hot-reload: implememnt auto session/state backup on reload and display error stack in a popup
This commit is contained in:
parent
bcf80a1668
commit
42bd16df09
5 changed files with 109 additions and 52 deletions
|
|
@ -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)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue