Merge pull request #1240 from sinyo-matu/master

add favicon error indicator
This commit is contained in:
Alexander Wang 2023-05-07 12:10:35 -07:00 committed by GitHub
commit 6b9c4fa234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
d2cli/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -28,7 +28,7 @@ function init(reconnectDelay) {
// we can't just set `d2SVG.innerHTML = msg.svg` need to parse this as xml not html // we can't just set `d2SVG.innerHTML = msg.svg` need to parse this as xml not html
const parsedXML = new DOMParser().parseFromString(msg.svg, "text/xml"); const parsedXML = new DOMParser().parseFromString(msg.svg, "text/xml");
d2SVG.replaceChildren(parsedXML.documentElement); d2SVG.replaceChildren(parsedXML.documentElement);
changeFavicon("./static/favicon.ico");
const svgEl = d2SVG.querySelector("#d2-svg"); const svgEl = d2SVG.querySelector("#d2-svg");
// just use inner SVG in watch mode // just use inner SVG in watch mode
svgEl.parentElement.replaceWith(svgEl); svgEl.parentElement.replaceWith(svgEl);
@ -56,6 +56,7 @@ function init(reconnectDelay) {
if (msg.err) { if (msg.err) {
d2ErrDiv.innerText = msg.err; d2ErrDiv.innerText = msg.err;
d2ErrDiv.style.display = "block"; d2ErrDiv.style.display = "block";
changeFavicon("./static/favicon-err.ico");
d2ErrDiv.scrollIntoView(); d2ErrDiv.scrollIntoView();
} }
}; };
@ -73,3 +74,8 @@ function init(reconnectDelay) {
}, reconnectDelay); }, reconnectDelay);
}; };
} }
const changeFavicon = function (iconURL) {
const faviconLink = document.getElementById("favicon");
faviconLink.href = iconURL;
};

View file

@ -429,6 +429,7 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {
<title>%s</title> <title>%s</title>
<script src="./static/watch.js"></script> <script src="./static/watch.js"></script>
<link rel="stylesheet" href="./static/watch.css"> <link rel="stylesheet" href="./static/watch.css">
<link id="favicon" rel="icon" href="./static/favicon.ico">
</head> </head>
<body data-d2-dev-mode=%t> <body data-d2-dev-mode=%t>
<div id="d2-err" style="display: none"></div> <div id="d2-err" style="display: none"></div>