Skip to content

Commit b2df83b

Browse files
committed
Starting to constrain logView to limited number of lines. Problems with log scrolling when trimming leading lines.
1 parent 147dd28 commit b2df83b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const mDbug = mcStatus + mdLog + mdConsole;
8484
const mDeep = mcVerbose + mdConsole;
8585
const mAll = mcUser + mdDisplay + mdLog + mdConsole;
8686

87+
let logLines = [];
8788
//TODO determine if more messages should be converted to mUser - instead of manually socket.send()'ing them
8889
//TODO allow this to be further filtered with includes/excludes set by app options at runtime
8990
//TODO provide mechanism for this to be a downloadable date-stamped file.
@@ -116,9 +117,14 @@ function log(text = "", type = mStat, socket = null, direction = 0) {
116117
//Send to Launcher log view
117118
let logView = $('log');
118119
//Note scroll position (to see if user has scrolled up), append message, then auto-scroll (down) if bottom was previously in view
119-
let scroll = (logView.scrollTop+1 >= logView.scrollHeight-logView.clientHeight);
120-
logView.innerHTML += stamp(verboseLogging) + text + '<br>';
121-
if (scroll) {logView.scrollTo(0, logView.scrollHeight)}
120+
console.log(logView.scrollTop);
121+
let scrollTop = logView.scrollTop;
122+
let scroll = (scrollTop+1 >= logView.scrollHeight-logView.clientHeight);
123+
logLines.push(stamp(verboseLogging) + text + '<br>');
124+
if (logLines.length > 40) {logLines.shift()}
125+
logView.innerHTML = logLines.join('');
126+
if (scroll) {logView.scrollTo(0, logView.scrollHeight)} else {if (scrollTop !== logView.ScrollTop) {logView.scrollTo(0, scrollTop-(logView.scrollTop-scrollTop))}}
127+
logView.style.
122128
}
123129
//Send to Launcher console window
124130
if (type & mdConsole) {console.log(stamp(true) + text)}
@@ -228,12 +234,13 @@ document.addEventListener('DOMContentLoaded', function() {
228234

229235
// TODO: re-write this to use onblur and/or onchange to auto-save.
230236
$('refresh-connection').onclick = function() {
231-
disconnect();
232-
closeServer();
233-
if(chrome.storage) {
234-
chrome.storage.sync.set({'s_port':$('bpc-port').value, 's_url':$('bpc-url').value}, function() {if (chrome.runtime.lastError) {storageError()}});
235-
}
236-
connect();
237+
$('log').innerHTML = '';
238+
// disconnect();
239+
// closeServer();
240+
// if(chrome.storage) {
241+
// chrome.storage.sync.set({'s_port':$('bpc-port').value, 's_url':$('bpc-url').value}, function() {if (chrome.runtime.lastError) {storageError()}});
242+
// }
243+
// connect();
237244
};
238245

239246
$('netmask').addEventListener("blur", function() {

loader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function loadPropeller(sock, portName, action, payload, debug) {
140140
updatePort(port, {mode: "programming", bSocket: sock});
141141
connect = function() {return Promise.resolve()};
142142
}
143+
let startTime = Date.now();
143144
// Use connection to download application to the Propeller
144145
connect()
145146
.then(function() {listen(port, true)}) //Enable listener
@@ -168,7 +169,9 @@ function loadPropeller(sock, portName, action, payload, debug) {
168169
.catch(function(e) {log(e.message, mAll, sock, -1)})
169170
.then(function() {if (port.isWireless) return closePort(port, false)})
170171
.catch(function(e) {log(e.message, mAll, sock, -1)})
172+
.then(function() {let stopTime = Date.now(); log('Processing time: ' + (stopTime-startTime).toString().slice(-5));})
171173
.then(function() {resumeTimedEvents()}) // Resume timed events that were halted earlier
174+
.catch(function() {let stopTime = Date.now(); log('Processing time: ' + (stopTime-startTime).toString().slice(-5));})
172175
.catch(function() {resumeTimedEvents()});
173176
} else {
174177
// Port not found

0 commit comments

Comments
 (0)