From d13bbf10983d9f2471764d3fa795b0358fc6afb9 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 11 Sep 2023 21:31:01 +0200 Subject: [PATCH 1/5] Improve logs and error check --- rootfs/usr/share/www/static/scripts.js | 14 +++++++----- rootfs/usr/share/www/static/styles.css | 30 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/rootfs/usr/share/www/static/scripts.js b/rootfs/usr/share/www/static/scripts.js index c7b4032..c026020 100644 --- a/rootfs/usr/share/www/static/scripts.js +++ b/rootfs/usr/share/www/static/scripts.js @@ -70,12 +70,14 @@ function testAvailable() { }, scheduleTry); } +var errorCheck = /^[\d -:]+ERROR(.*)/gm + function fetchLogs() { fetch("/observer/logs").then(function (res) { if (res.ok) { res.text().then(function (text) { var logElement = document.getElementById("log"); - if (text.includes("ERROR")) { + if (errorCheck.test(text)) { document.body.classList.add("error"); document.getElementById("show_logs").classList.add("hidden"); logElement.showFull = true; @@ -84,10 +86,12 @@ function fetchLogs() { return; } var scrolledDown = logElement.scrollTop + logElement.clientHeight === logElement.scrollHeight; - logElement.innerText = text - .replace(/\s[A-Z]+\s\(\w+\)\s\[[\w.]+\]/gi, "") - .replace(/\d{2}-\d{2}-\d{2}\s/gi, "") - .replace(/\d{2}:\d{2}:\d{2}\s/gi, ""); + logElement.innerHTML = text + .replace(/^[\[\d \-:\]]*/gm, "") + .replace(/^INFO\s\(\w+\)\s/gm, "") + .replace(/^WARNING\s\(\w+\)\s/gm, "") + .replace(/^ERROR\s\(\w+\)\s/gm, "") + .replace(/\n/gm, "\n"); if (scrolledDown) { // Scroll content down if it was already scrolled down logElement.scrollTop = logElement.scrollHeight; diff --git a/rootfs/usr/share/www/static/styles.css b/rootfs/usr/share/www/static/styles.css index 6108be5..a640a5e 100644 --- a/rootfs/usr/share/www/static/styles.css +++ b/rootfs/usr/share/www/static/styles.css @@ -45,6 +45,7 @@ body { display: flex; align-items: center; } + .alert::after { position: absolute; top: 0; @@ -57,11 +58,13 @@ body { border-radius: 4px; background-color: #db4437; } + .alert-icon { fill: #db4437; width: 24px; flex-shrink: 0; } + .alert-content { font-size: 14px; text-align: left; @@ -276,9 +279,11 @@ button.icon { .block:after { border-radius: 12px; } + .link-list { padding: 8px 0; } + .link { width: 100%; height: 100%; @@ -343,6 +348,22 @@ pre:empty { display: none; } +/* pre span:nth-child(even) { + background: green; +} */ + +pre .info { + color: #039be5; +} + +pre .error { + color: #db4437; +} + +pre .warning { + color: #ffa600; +} + dialog { background-color: #ffffff; border: none !important; @@ -359,9 +380,9 @@ dialog::backdrop { dialog button { width: 48px; - height: 48px; - padding: 12px; - margin: -12px; + height: 48px; + padding: 12px; + margin: -12px; border-radius: 50%; } @@ -417,7 +438,8 @@ dialog button svg { gap: 16px; } -.app-qr a, .app-qr img { +.app-qr a, +.app-qr img { flex: 1; } From a163a7798131032c3dc6b18b600bbdbc30608124 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 11 Sep 2023 21:39:15 +0200 Subject: [PATCH 2/5] Add download logs button --- rootfs/usr/share/www/static/scripts.js | 13 ++++++++++++- rootfs/usr/share/www/static/styles.css | 8 -------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rootfs/usr/share/www/static/scripts.js b/rootfs/usr/share/www/static/scripts.js index c026020..2486d3b 100644 --- a/rootfs/usr/share/www/static/scripts.js +++ b/rootfs/usr/share/www/static/scripts.js @@ -79,7 +79,7 @@ function fetchLogs() { var logElement = document.getElementById("log"); if (errorCheck.test(text)) { document.body.classList.add("error"); - document.getElementById("show_logs").classList.add("hidden"); + document.getElementById("show_logs").innerText = "Download raw logs"; logElement.showFull = true; } if (!logElement.showFull) { @@ -117,6 +117,17 @@ fetchLogs(); document.getElementById("show_logs").addEventListener("click", toggleLogs); function toggleLogs(event) { + if (document.body.classList.contains("error")) { + const a = document.createElement("a"); + a.target = "_blank"; + a.href = "/observer/logs"; + a.download = "logs.txt"; + + document.body.appendChild(a); + a.dispatchEvent(new MouseEvent("click")); + document.body.removeChild(a); + return; + } var logElement = document.getElementById("log"); logElement.showFull = !logElement.showFull; if (logElement.showFull) { diff --git a/rootfs/usr/share/www/static/styles.css b/rootfs/usr/share/www/static/styles.css index a640a5e..1c833ed 100644 --- a/rootfs/usr/share/www/static/styles.css +++ b/rootfs/usr/share/www/static/styles.css @@ -72,10 +72,6 @@ body { margin-right: 0; } -.hidden { - display: none; -} - .header { text-align: center; margin-top: 32px; @@ -348,10 +344,6 @@ pre:empty { display: none; } -/* pre span:nth-child(even) { - background: green; -} */ - pre .info { color: #039be5; } From 812dd3d21b76798a84de0235aad22a6142258f5e Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 11 Sep 2023 21:41:31 +0200 Subject: [PATCH 3/5] fix logs border in dark mode --- rootfs/usr/share/www/static/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/usr/share/www/static/styles.css b/rootfs/usr/share/www/static/styles.css index 1c833ed..9b730c2 100644 --- a/rootfs/usr/share/www/static/styles.css +++ b/rootfs/usr/share/www/static/styles.css @@ -441,7 +441,7 @@ dialog button svg { background-color: #111111; } - .content { + .content, pre { background-color: #1c1c1c; border-color: rgba(225, 225, 225, 0.12); } From 274c1cec067f2d9aa7a81861da3f40ae474375b7 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 11 Sep 2023 21:44:55 +0200 Subject: [PATCH 4/5] format --- rootfs/usr/share/www/index.html | 15 ++++++++------- rootfs/usr/share/www/static/scripts.js | 2 +- rootfs/usr/share/www/static/styles.css | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rootfs/usr/share/www/index.html b/rootfs/usr/share/www/index.html index ac21a30..864cee8 100644 --- a/rootfs/usr/share/www/index.html +++ b/rootfs/usr/share/www/index.html @@ -27,13 +27,14 @@

This may take up to 20 minutes

Error installing Home Assistant