From 0b424fd6be765737f11febcc95eee30b5ee22ec8 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 21 Aug 2018 15:46:46 +0100 Subject: [PATCH] Add history to console log window --- console.htm | 22 +++++++++++++--------- main.js | 13 ++++++++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/console.htm b/console.htm index 7850de4..a707ca9 100644 --- a/console.htm +++ b/console.htm @@ -8,24 +8,28 @@ - +
diff --git a/main.js b/main.js index 24312cf..e027dc2 100755 --- a/main.js +++ b/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; });