MCPcopy
hub / github.com/stemdeckapp/stemdeck / wireNetworkSetting

Function wireNetworkSetting

static/js/catalog.js:1896–1975  ·  view source on GitHub ↗
(overlay)

Source from the content-addressed store, hash-verified

1894}
1895
1896async function wireNetworkSetting(overlay) {
1897 const input = overlay.querySelector(".net-access-input");
1898 const netWrap = overlay.querySelector(".settings-net");
1899 const qrWrap = overlay.querySelector(".settings-net-qr");
1900 if (!input) return;
1901
1902 let enabled = false;
1903 let addresses = [];
1904 try {
1905 const r = await fetch("/api/settings", { cache: "no-store" });
1906 if (r.ok) {
1907 const data = await r.json();
1908 enabled = data.allow_network === true;
1909 addresses = Array.isArray(data.lan_addresses) ? data.lan_addresses : [];
1910 }
1911 } catch { /* leave defaults */ }
1912
1913 // QR codes: one per LAN address, each encodes the /mobile/ URL so the
1914 // phone camera opens StemDeck directly. Cards start blurred so an open
1915 // camera app on a nearby device doesn't scan them before you're ready.
1916 if (qrWrap) {
1917 qrWrap.textContent = "";
1918 if (addresses.length) {
1919 const hint = document.createElement("p");
1920 hint.className = "qr-hint";
1921 hint.textContent = "Blurred so your camera doesn't get too excited. Tap to reveal.";
1922 qrWrap.appendChild(hint);
1923 const row = document.createElement("div");
1924 row.className = "qr-cards-row";
1925 for (const a of addresses) {
1926 const mobileUrl = `${a}/mobile/`;
1927 const card = document.createElement("div");
1928 card.className = "qr-card qr-blurred";
1929 card.title = "Tap to unblur";
1930 card.addEventListener("click", () => card.classList.toggle("qr-blurred"));
1931 const img = document.createElement("img");
1932 img.src = `/api/qr?url=${encodeURIComponent(mobileUrl)}`;
1933 img.alt = `QR code for ${mobileUrl}`;
1934 img.width = 130;
1935 img.height = 130;
1936 const label = document.createElement("div");
1937 label.className = "qr-label";
1938 label.textContent = mobileUrl;
1939 const imgWrap = document.createElement("div");
1940 imgWrap.className = "qr-img-wrap";
1941 imgWrap.appendChild(img);
1942 card.append(imgWrap, label);
1943 row.appendChild(card);
1944 }
1945 qrWrap.appendChild(row);
1946 } else {
1947 const span = document.createElement("span");
1948 span.className = "settings-net-empty";
1949 span.textContent = "No local network connection detected.";
1950 qrWrap.appendChild(span);
1951 }
1952 }
1953

Callers 1

openLibraryEditorFunction · 0.85

Calls 1

refreshFunction · 0.85

Tested by

no test coverage detected