Merge pull request #390 from MartinHN/pr/debug-autoreload

add integrated html error and reloading when debuging
This commit is contained in:
jean-emmanuel 2018-10-20 15:24:09 +02:00 • committed by GitHub
commit a82b9fa899
7 changed files with 161 additions and 6 deletions

View file

@ -5,11 +5,13 @@ var path = require('path'),
{ipc} = require('./server'),
{deepCopy} = require('./utils'),
theme = require('./theme'),
chokidar = require('chokidar')
chokidar = require('chokidar'),
{BrowserWindow} = require('electron')
var openedSessions = {},
widgetHashTable = {},
lastSavingClient
lastSavingClient,
sessionBackups = {}
module.exports = {
@ -20,6 +22,11 @@ module.exports = {
ipc.send('readOnly')
}
if (data.backupId && sessionBackups[data.backupId]) {
ipc.send('loadBackup', sessionBackups[data.backupId])
return
}
if (settings.read('newSession')) {
ipc.send('sessionNew')
return
@ -295,6 +302,24 @@ module.exports = {
window.setFullScreen(!window.isFullScreen())
},
reload: function(data) {
ipc.send('reload')
},
storeBackup: function(data) {
sessionBackups[data.backupId] = data
},
deleteBackup: function(data) {
delete sessionBackups[data]
},
reloadCss:function(){
theme.load()
ipc.send('reloadCss')
@ -310,5 +335,10 @@ module.exports = {
errorLog: function(data) {
console.error(data)
},
errorPopup: function(data) {
ipc.send('error', data)
}
}

View file

@ -38,7 +38,7 @@ module.exports = function(options={}) {
}
})
window.webContents.on('will-navigate', (event)=>event.preventDefault())
// window.webContents.on('will-navigate', (event)=>event.preventDefault())
window.webContents.on('new-window', (event)=>event.preventDefault())
if (options.fullscreen) {

View file

@ -76,6 +76,7 @@
"node": ">=6"
},
"devDependencies": {
"ansi-to-html": "^0.6.6",
"watchify": "^3.11.0"
}
}

View file

@ -10,6 +10,7 @@ var browserify = require('browserify'),
prod = process.argv.indexOf('--prod') != -1,
fast = process.argv.indexOf('--fast') != -1,
watch = process.argv.indexOf('--watch') != -1,
autoRefresh = process.argv.indexOf('--auto-refresh') != -1,
b
var inputPath = path.resolve(__dirname + '/../src/browser/js/index.js'),
@ -60,10 +61,48 @@ if (watch) {
bundle()
if (autoRefresh) {
var Convert = require('ansi-to-html')
var convert = new Convert()
var WS = require('../app/node_modules/ws')
function send(msg, data){
var ipc = new WS('ws://127.0.0.1:8080/dev')
ipc.on('error', ()=>{})
ipc.on('open', ()=>{
ipc.send(JSON.stringify([msg, data]))
ipc.close()
})
}
}
function bundle() {
var output = b.bundle()
output.on('error', function(err) {console.error(new Error(err))})
output.on('end', (err)=> {
console.log('Build successful', autoRefresh ? 'reloading...' : '')
if (autoRefresh) send('reload')
})
output.on('error', (err)=> {
console.error(err.stack)
send('errorPopup',
'<div class="error-stack">' +
convert.toHtml(
err.stack
.replace(/\n\s*at Parser.*/g, '') // remove useless stack
.replace(new RegExp(path.resolve(__dirname + '/..'), 'g'),'.') // shorten file path
.trim()
.replace('\n','\n\n') // add 1 new line after 1st line
) +
'</div>'
)
})
if (!fast) output.pipe(exorcist(outputPath + '.map'))

View file

@ -4,7 +4,10 @@ var utils = require('../ui/utils'),
widgetManager = require('../managers/widgets'),
state = require('../managers/state'),
editor = require('../editor/'),
locales = require('../locales')
locales = require('../locales'),
{deepCopy} = require('../utils'),
sidepanel = require('../ui/sidepanel'),
ipc = require('./')
module.exports = {
@ -81,11 +84,77 @@ 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(),
history: editor.history,
historyState: editor.historyState,
editorEnabled: editor.enabled,
sidepanelOpened: document.getElementById('sidepanel').classList.contains('sidepanel-open')
})
// 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)
editor.historySession = deepCopy(data.session)
editor.history = data.history
editor.historyState = data.historyState
if (data.editorEnabled) editor.enable()
if (data.sidepanelOpened) sidepanel.open()
ipc.send('deleteBackup', data.backupId)
})
}
}

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)

View file

@ -572,6 +572,21 @@ body {
}
}
.error-stack {
padding:10rem;
user-select:initial;
cursor: initial;
* {
user-select:initial;
cursor: initial;
}
overflow:auto;
background: var(--color-bg);
white-space:pre;
font-family: monospace;
font-weight:bold;
}
.translation-missing {
color: #ff00ff;
}