/** * Shell entry point — loaded on every page. * * Registers the three header web components: * * * */ import { RStackIdentity } from "../shared/components/rstack-identity"; import { RStackNotificationBell } from "../shared/components/rstack-notification-bell"; import { RStackAppSwitcher } from "../shared/components/rstack-app-switcher"; import { RStackSpaceSwitcher } from "../shared/components/rstack-space-switcher"; import { RStackTabBar } from "../shared/components/rstack-tab-bar"; import { RStackMi } from "../shared/components/rstack-mi"; import { RStackSpaceSettings } from "../shared/components/rstack-space-settings"; import { RStackOfflineIndicator } from "../shared/components/rstack-offline-indicator"; import { rspaceNavUrl } from "../shared/url-helpers"; import { TabCache } from "../shared/tab-cache"; import { RSpaceOfflineRuntime } from "../shared/local-first/runtime"; // Expose URL helper globally (used by shell inline scripts + components) (window as any).__rspaceNavUrl = rspaceNavUrl; // Expose TabCache for inline shell script to instantiate (window as any).__RSpaceTabCache = TabCache; // Register all header components RStackIdentity.define(); RStackNotificationBell.define(); RStackAppSwitcher.define(); RStackSpaceSwitcher.define(); RStackTabBar.define(); RStackMi.define(); RStackSpaceSettings.define(); RStackOfflineIndicator.define(); // ── Offline Runtime ── // Instantiate the shared runtime from the space slug on the tag. // Components access it via window.__rspaceOfflineRuntime. const spaceSlug = document.body?.getAttribute("data-space-slug"); if (spaceSlug && spaceSlug !== "demo") { const runtime = new RSpaceOfflineRuntime(spaceSlug); (window as any).__rspaceOfflineRuntime = runtime; runtime.init().catch((e: unknown) => { console.warn("[shell] Offline runtime init failed — REST fallback only:", e); }); // Flush pending writes before the page unloads window.addEventListener("beforeunload", () => { runtime.flush(); }); } // Reload space list when user signs in/out (to show/hide private spaces) document.addEventListener("auth-change", () => { const spaceSwitcher = document.querySelector("rstack-space-switcher") as any; spaceSwitcher?.reload?.(); // If signed out, redirect to homepage const session = localStorage.getItem("encryptid_session"); if (!session) { window.location.href = "/"; } });