diff --git a/.gitignore b/.gitignore index 5e9693e..8d303a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__ pysssss.json -user/autocomplete.txt \ No newline at end of file +user/autocomplete.txt +web/js/assets/favicon.user.ico +web/js/assets/favicon-active.user.ico \ No newline at end of file diff --git a/web/js/faviconStatus.js b/web/js/faviconStatus.js index b68eafc..15bebdc 100644 --- a/web/js/faviconStatus.js +++ b/web/js/faviconStatus.js @@ -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, () => {