Skip to content

Commit 5183e78

Browse files
fhirschmannclaude
andcommitted
feat: live-updating log dialog
The log refreshes every two seconds while the dialog is open and follows the end of the log unless the user scrolled up. Also fixes stacking refresh-button handlers on repeated opening. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f8b477b commit 5183e78

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎html/management.html‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,12 +4484,19 @@ <h5 class="modal-title" data-i18n="tools.nvs.erase.title"></h5>
44844484
}
44854485
$('#modalInfoContent').html(content);
44864486
}
4487+
var liveLogInterval;
44874488
async function fetchLog() {
44884489
let logtext = await (await fetch("http://" + host + "/log")).text();
4489-
$('#modalLogContent').text(logtext);
4490-
jQuery('#modalLogContent').animate({
4491-
scrollTop: 999999
4492-
});
4490+
const content = document.getElementById('modalLogContent');
4491+
if (content.textContent === logtext) {
4492+
return;
4493+
}
4494+
// keep the scroll position unless the user is following the end of the log
4495+
const follow = (content.scrollHeight - content.scrollTop - content.clientHeight) < 40;
4496+
content.textContent = logtext;
4497+
if (follow) {
4498+
content.scrollTop = content.scrollHeight;
4499+
}
44934500
}
44944501

44954502
function setTitle(newTitle) {
@@ -4542,9 +4549,17 @@ <h5 class="modal-title" data-i18n="tools.nvs.erase.title"></h5>
45424549
fetchLog();
45434550
$('.modal-title').text(i18next.t("log"));
45444551
$("#modalLogContent").css("font-family", "monospace");
4545-
$('#modalLogRefresh').on('click', fetchLog);
45464552
new bootstrap.Modal(document.getElementById('modalLog')).toggle();
45474553
})
4554+
$('#modalLogRefresh').on('click', fetchLog);
4555+
/* live-update the log while the dialog is open */
4556+
$('#modalLog').on('shown.bs.modal', function () {
4557+
clearInterval(liveLogInterval);
4558+
liveLogInterval = setInterval(fetchLog, 2000);
4559+
});
4560+
$('#modalLog').on('hidden.bs.modal', function () {
4561+
clearInterval(liveLogInterval);
4562+
});
45484563
$('#modalLogDownload').on('click', function () {
45494564
const blob = new Blob([document.getElementById('modalLogContent').textContent], {
45504565
type: 'text/plain'

0 commit comments

Comments
 (0)