Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(desktop): never a blank window when the app fails to load
Salman Qureshi418b771e2ae2
diff --git a/apps/desktop/index.html b/apps/desktop/index.htmlindex edf137a5..186d90cb 100644--- a/apps/desktop/index.html+++ b/apps/desktop/index.html@@ -8,6 +8,7 @@</head><body><div id="root"></div>+ <script src="/boot-guard.js"></script><script type="module" src="/src/main.tsx"></script></body></html>diff --git a/apps/desktop/public/boot-guard.js b/apps/desktop/public/boot-guard.jsnew file mode 100644index 00000000..1a29b8d8--- /dev/null+++ b/apps/desktop/public/boot-guard.js@@ -0,0 +1,53 @@+/*+ * Never a blank window. If the app's code fails to load (a missing file,+ * a failed import, a crash before the first render), show what happened+ * and a way out, instead of an empty screen. main.tsx sets+ * window.__mercuryBooted once the app has started.+ */+(function () {+ // The voice capsule is a tiny see-through window: nothing to show there.+ if (/[?&]surface=notch\b/.test(location.search)) return;+ var problem = null;+ function show() {+ if (window.__mercuryBooted || document.getElementById("boot-failure")) return;+ var dark = !window.matchMedia || window.matchMedia("(prefers-color-scheme: dark)").matches;+ var box = document.createElement("div");+ box.id = "boot-failure";+ box.setAttribute("role", "alert");+ box.style.cssText = "position:fixed;inset:0;display:flex;align-items:center;justify-content:center;padding:24px;font:14px -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;" ++ (dark ? "background:#0b0d0c;color:#e6e8e7" : "background:#fafafa;color:#1a1c1b");+ var card = document.createElement("div");+ card.style.cssText = "max-width:460px;text-align:center";+ var title = document.createElement("div");+ title.textContent = "Mercury couldn't start";+ title.style.cssText = "font-size:17px;font-weight:600;margin-bottom:8px";+ var detail = document.createElement("div");+ detail.textContent = problem || "The app took too long to load.";+ detail.style.cssText = "opacity:.7;margin-bottom:18px;word-break:break-word;font-family:ui-monospace,monospace;font-size:12px";+ var button = document.createElement("button");+ button.textContent = "Reload";+ button.style.cssText = "padding:8px 18px;border-radius:8px;border:0;background:#22C98B;color:#06110c;font-weight:600;cursor:pointer";+ button.onclick = function () { location.reload(); };+ card.appendChild(title);+ card.appendChild(detail);+ card.appendChild(button);+ box.appendChild(card);+ document.body.appendChild(box);+ }+ function fail(message) {+ if (window.__mercuryBooted) return;+ problem = problem || message;+ show();+ }+ // Capture also catches a script that couldn't be fetched.+ window.addEventListener("error", function (e) {+ var target = e.target;+ if (target && target !== window && target.tagName === "SCRIPT") fail("Couldn't load " + (target.src || "the app's code") + ".");+ else if (e.message) fail(e.message);+ }, true);+ window.addEventListener("unhandledrejection", function (e) {+ var r = e.reason;+ fail(r && r.message ? r.message : String(r));+ });+ setTimeout(show, 15000);+})();diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsxindex 0d4aa690..3ce3bd41 100644--- a/apps/desktop/src/main.tsx+++ b/apps/desktop/src/main.tsx@@ -13,3 +13,5 @@ ReactDOM.createRoot(document.getElementById("root")!).render({surface === "notch" ? <NotchApp /> : <App />}</React.StrictMode>);+// The code loaded and the app started: public/boot-guard.js stands down.+(window as Window & { __mercuryBooted?: boolean }).__mercuryBooted = true;