MCPcopy
hub / github.com/pythongosssss/ComfyUI-Custom-Scripts / setup

Function setup

web/js/faviconStatus.js:9–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7app.registerExtension({
8 name: "pysssss.FaviconStatus",
9 async setup() {
10 let link = document.querySelector("link[rel~='icon']");
11 if (!link) {
12 link = document.createElement("link");
13 link.rel = "icon";
14 document.head.appendChild(link);
15 }
16
17 const getUrl = (active, user) => new URL(`assets/favicon${active ? "-active" : ""}${user ? ".user" : ""}.ico`, import.meta.url);
18 const testUrl = async (active) => {
19 const url = getUrl(active, true);
20 const r = await fetch(url, {
21 method: "HEAD",
22 });
23 if (r.status === 200) {
24 return url;
25 }
26 return getUrl(active, false);
27 };
28 const activeUrl = await testUrl(true);
29 const idleUrl = await testUrl(false);
30
31 let executing = false;
32 const update = () => (link.href = executing ? activeUrl : idleUrl);
33
34 for (const e of ["execution_start", "progress"]) {
35 api.addEventListener(e, () => {
36 executing = true;
37 update();
38 });
39 }
40
41 api.addEventListener("executing", ({ detail }) => {
42 // null will be sent when it's finished
43 executing = !!detail;
44 update();
45 });
46
47 api.addEventListener("status", ({ detail }) => {
48 let title = "ComfyUI";
49 if (detail && detail.exec_info.queue_remaining) {
50 title = `(${detail.exec_info.queue_remaining}) ${title}`;
51 }
52 document.title = title;
53 update();
54 executing = false;
55 });
56 update();
57 },
58});

Callers

nothing calls this directly

Calls 2

testUrlFunction · 0.85
updateFunction · 0.85

Tested by

no test coverage detected