Support custom favicon

This commit is contained in:
pythongosssss
2024-03-24 18:22:37 +00:00
parent 8975a4dfd8
commit 764f0d0cc5
2 changed files with 21 additions and 3 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
__pycache__
pysssss.json
user/autocomplete.txt
user/autocomplete.txt
web/js/assets/favicon.user.ico
web/js/assets/favicon-active.user.ico
+18 -2
View File
@@ -6,7 +6,7 @@ import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "pysssss.FaviconStatus",
setup() {
async setup() {
let link = document.querySelector("link[rel~='icon']");
if (!link) {
link = document.createElement("link");
@@ -14,8 +14,24 @@ app.registerExtension({
document.head.appendChild(link);
}
const getUrl = (active, user) => new URL(`assets/favicon${active ? "-active" : ""}${user ? ".user" : ""}.ico`, import.meta.url);
const testUrl = async (active) => {
const url = getUrl(active, true);
const r = await fetch(url, {
method: "HEAD",
});
if (r.status === 200) {
return url;
}
return getUrl(active, false);
};
const activeUrl = await testUrl(true);
const idleUrl = await testUrl(false);
console.log(activeUrl, idleUrl);
let executing = false;
const update = () => (link.href = new URL(`assets/favicon${executing ? "-active" : ""}.ico`, import.meta.url));
const update = () => (link.href = executing ? activeUrl : idleUrl);
for (const e of ["execution_start", "progress"]) {
api.addEventListener(e, () => {