kopia lustrzana https://github.com/dceejay/electron-node-red
Add history to console log window
rodzic
80ac176db6
commit
0b424fd6be
22
console.htm
22
console.htm
|
@ -8,24 +8,28 @@
|
|||
</head>
|
||||
<body style="margin:0;" >
|
||||
<font style="font-family:'Helvetica Neue', Arial, Helvetica, sans-serif; font-size:9pt;">
|
||||
<div id="header" style="background-color:#910000; color:white; font-size:larger; height:16px; padding:8px;">Most recent messages at top<input type="button" style="float:right;" value="Clear Log" onclick="clearList()";/></div>
|
||||
<div id="header" style="background-color:#910000; position:fixed; height:16px; width:100%; padding:8px;"><input type="button" value="Clear Log" onclick="clearList()";/></div>
|
||||
<div id="debug" style="padding:4px; padding-left:8px;"></div>
|
||||
</font>
|
||||
<script>
|
||||
const logLength = 250;
|
||||
const { ipcRenderer } = require('electron');
|
||||
const ipc = require('electron').ipcRenderer;
|
||||
var list = "";
|
||||
var list = [];
|
||||
var clearList = function() {
|
||||
list = "";
|
||||
document.getElementById("debug").innerHTML = list;
|
||||
list = [];
|
||||
document.getElementById("debug").innerHTML = "";
|
||||
}
|
||||
|
||||
ipc.on('logBuff', (event, data) => {
|
||||
list = data;
|
||||
document.getElementById("debug").innerHTML = list.join("<br/>");
|
||||
});
|
||||
ipc.on('debugMsg', (event, data) => {
|
||||
var ts = (new Date(data.timestamp)).toISOString();
|
||||
ts = ts.replace("Z"," ").replace("T"," ");
|
||||
list = ts+" : "+data.msg+"<br/>"+list;
|
||||
document.getElementById("debug").innerHTML = list;
|
||||
if (list.length > 50000) { list = list.substr(0,40000); }
|
||||
list.push(data);
|
||||
if (list.length > logLength) { list.shift(); }
|
||||
document.getElementById("debug").innerHTML = list.join("<br/>");
|
||||
window.scrollTo(0,document.body.scrollHeight);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
13
main.js
13
main.js
|
@ -64,6 +64,8 @@ console.log("Setting UserDir to ",userdir);
|
|||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
let conWindow;
|
||||
let logBuffer = [];
|
||||
let logLength = 250;
|
||||
|
||||
// Create the settings object - see default settings.js file for other options
|
||||
var settings = {
|
||||
|
@ -79,7 +81,12 @@ var settings = {
|
|||
metrics: false,
|
||||
handler: function() {
|
||||
return function(msg) {
|
||||
if (conWindow) { conWindow.webContents.send('debugMsg', msg); }
|
||||
var ts = (new Date(msg.timestamp)).toISOString();
|
||||
ts = ts.replace("Z"," ").replace("T"," ");
|
||||
var line = ts+" : "+msg.msg;
|
||||
logBuffer.push(line);
|
||||
if (conWindow) { conWindow.webContents.send('debugMsg', line); }
|
||||
if (logBuffer.length > logLength) { logBuffer.shift(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,9 +194,9 @@ function createConsole() {
|
|||
slashes: true
|
||||
}))
|
||||
conWindow.webContents.on('did-finish-load', () => {
|
||||
//console.log("LOADED CONSOLE");
|
||||
conWindow.webContents.send('debugMsg', "Ready");
|
||||
conWindow.webContents.send('logBuff', logBuffer);
|
||||
});
|
||||
|
||||
conWindow.on('closed', function() {
|
||||
conWindow = null;
|
||||
});
|
||||
|
|
Ładowanie…
Reference in New Issue