Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(update): one Settings cue, no toast and no floating badge (#161)

Abdurrahman Fakhrul1c74603f3e7f
diff --git a/app/api/sw/route.ts b/app/api/sw/route.ts
index e5774258..f1af50eb 100644
--- a/app/api/sw/route.ts
+++ b/app/api/sw/route.ts
@@ -1,12 +1,13 @@
import { NextResponse } from "next/server";
// Serve the service worker dynamically so its bytes change every deploy: the
-// CACHE name (and header comment) embed the build id. A static public/sw.js is
-// byte-identical across deploys, so the browser never sees an "update" and the
-// "new version → reload" toast never fires (it only ever showed once, during a
-// cache-name bump). With the id baked in, each deploy is a new SW → updatefound
-// → waiting → toast (see app/register-sw.tsx). Caches ONLY icons + manifest;
-// never JS chunks/HTML, so a redeploy can't strand a stale chunk.
+// CACHE name (and header comment) embed the build id. With the id baked in, each
+// deploy is a genuinely new SW, so the browser installs it, it lands in waiting,
+// and it takes over when the user reloads or the browser retires the old worker.
+// Nothing prompts: the worker intentionally never self-activates and there is no
+// client cue (app/register-sw.tsx only registers it; Settings shows the update).
+// Caches ONLY icons + manifest; never JS chunks/HTML, so a redeploy can't strand
+// a stale chunk.
const BUILD_ID = process.env.NEXT_PUBLIC_BUILD_ID || "dev";
// Small illustrated app icons are pre-cached with the shell so the dock/taskbar
@@ -40,12 +41,10 @@ const CACHE = "mso-${BUILD_ID}";
// the comment above promises this never does.
const ASSETS = ${JSON.stringify(["/icon.svg", "/icon-maskable.svg", "/manifest.webmanifest", ...APP_ICON_ASSETS, ...PLATFORM_APP_ICON_ASSETS, ...OFFICIAL_BRAND_ICON_ASSETS])};
self.addEventListener("install", (e) => {
- // Do NOT skipWaiting here. Auto-activating skipped the "waiting" state, so the
- // client's "new version" toast (which needs reg.waiting) never showed and the
- // update relied on a silent controllerchange reload that did not fire on mobile
- // PWAs. Now the new SW sits in waiting → client toasts → user taps Reload →
- // SKIP_WAITING message (below) activates it → controllerchange reload. The
- // first-ever install (no old SW controlling clients) still activates at once.
+ // Do NOT skipWaiting here, and nothing on the client sends SKIP_WAITING either.
+ // The new worker stays in waiting until the browser retires the old one (all
+ // tabs closed) or the user reloads, so a deploy never swaps assets mid-session.
+ // The update itself is surfaced only in Settings, which reads the release tag.
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS).catch(() => {})));
});
self.addEventListener("message", (e) => {
diff --git a/app/register-sw.tsx b/app/register-sw.tsx
index 0e4176cd..c7b19c98 100644
--- a/app/register-sw.tsx
+++ b/app/register-sw.tsx
@@ -46,41 +46,13 @@ async function recover() {
location.reload();
}
-// New SW is installed + waiting → offer a one-tap reload. The reload clears
-// caches and activates the waiting SW (SKIP_WAITING → controllerchange).
+// Registers the PWA service worker + a ChunkLoadError self-heal.
//
-// `toast` is imported HERE, not at module scope. RegisterSW sits in the ROOT
-// layout, and `@/features/appshell` re-exports the whole appshell barrel — so a
-// top-level import put the entire OS shell (window manager, 5 shells, 10 shell
-// features) into the static graph of every route, including public pages that
-// render nothing but text. Deferring it to the moment an update actually exists
-// keeps the shell out of the initial load and changes no behaviour: by then the
-// shell is either already loaded, or there is no toast surface to render into.
-async function promptUpdate(reg: ServiceWorkerRegistration) {
- const waiting = reg.waiting;
- if (!waiting || !navigator.serviceWorker.controller) return;
- let reloading = false;
- const { toast } = await import("@/features/appshell");
- toast("Versi baru tersedia.", {
- action: {
- label: "Reload",
- onClick: () => {
- navigator.serviceWorker.addEventListener(
- "controllerchange",
- () => {
- if (reloading) return;
- reloading = true;
- void clearCaches().then(() => location.reload());
- },
- { once: true },
- );
- waiting.postMessage({ type: "SKIP_WAITING" });
- },
- },
- });
-}
-
-// Registers the PWA service worker + update toast + a ChunkLoadError self-heal.
+// There is deliberately no update prompting here: the new worker stays in
+// waiting until the browser retires it (every tab closed), and the only in-app
+// update cue is Settings. Nobody posts SKIP_WAITING, so no controllerchange
+// reload guard is needed either: the page never swaps its controller under the
+// user's feet.
export function RegisterSW() {
useEffect(() => {
// Clear the guard after a healthy spell so a later genuine error can recover.
@@ -95,53 +67,15 @@ export function RegisterSW() {
window.addEventListener("error", onError);
window.addEventListener("unhandledrejection", onRejection);
- // SW update plumbing torn down on unmount.
- let updateTimer: number | undefined;
- let onVisible: (() => void) | undefined;
-
+ // Registration only: the worker owns the icon + manifest cache. No manual
+ // `reg.update()` polling and no activation handshake, so a deploy takes
+ // effect on the user's next reload instead of under a toast.
if ("serviceWorker" in navigator) {
- // The waiting SW activates only when the user taps the "new version" toast
- // (SKIP_WAITING). Control then passes to the new SW → controllerchange →
- // reload ONCE for fresh assets. Guarded to an UPDATE (a controller already
- // existed); the first-ever install must NOT reload. One-shot flag = no loop.
- if (navigator.serviceWorker.controller) {
- let refreshing = false;
- navigator.serviceWorker.addEventListener("controllerchange", () => {
- if (refreshing) return;
- refreshing = true;
- void clearCaches().then(() => location.reload());
- });
- }
- navigator.serviceWorker
- .register("/sw.js")
- .then((reg) => {
- // Already-queued update from a prior tab session.
- if (reg.waiting) void promptUpdate(reg);
- // A new SW starts installing → toast once it finishes.
- reg.addEventListener("updatefound", () => {
- const sw = reg.installing;
- if (!sw) return;
- sw.addEventListener("statechange", () => {
- if (sw.state === "installed") void promptUpdate(reg);
- });
- });
- // Mobile PWAs check for SW updates lazily — force it now, on focus, and
- // on a slow interval so a fresh deploy surfaces the toast promptly
- // instead of only on the next cold launch.
- void reg.update();
- updateTimer = window.setInterval(() => void reg.update(), 60_000);
- onVisible = () => {
- if (document.visibilityState === "visible") void reg.update();
- };
- document.addEventListener("visibilitychange", onVisible);
- })
- .catch(() => {});
+ navigator.serviceWorker.register("/sw.js").catch(() => {});
}
return () => {
clearTimeout(t);
- if (updateTimer) window.clearInterval(updateTimer);
- if (onVisible) document.removeEventListener("visibilitychange", onVisible);
window.removeEventListener("error", onError);
window.removeEventListener("unhandledrejection", onRejection);
};
diff --git a/frontend/slices/os-settings/components/update-shell-badge.tsx b/frontend/slices/os-settings/components/update-shell-badge.tsx
deleted file mode 100644
index 5f0bcecc..00000000
--- a/frontend/slices/os-settings/components/update-shell-badge.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-"use client";
-
-import { useEffect, useState } from "react";
-import { ArrowDownToLine } from "lucide-react";
-import { Button } from "@/components/ui/button";
-import { defineFeature, openWindow } from "@/features/appshell";
-import { useSession } from "@/features/auth";
-import { IS_DEMO } from "@/lib/demo";
-import { hasAvailableUpdate, readStatus } from "./update-status-client";
-
-/**
- * Shell-level "new version" affordance (UX-10) — dock-adjacent, not buried in
- * Account. Settings nav badge (`UpdateNavBadge`) stays as the in-app cue.
- */
-function UpdateShellBadge() {
- const { status, role } = useSession();
- const [available, setAvailable] = useState(false);
-
- useEffect(() => {
- if (IS_DEMO || status !== "in" || role !== "owner") return;
- let alive = true;
- readStatus(true)
- .then((next) => {
- if (alive) setAvailable(hasAvailableUpdate(next));
- })
- .catch(() => {
- if (alive) setAvailable(false);
- });
- return () => {
- alive = false;
- };
- }, [status, role]);
-
- if (IS_DEMO || status !== "in" || role !== "owner" || !available) return null;
-
- return (
- <div
- className="pointer-events-none fixed inset-x-0 z-[var(--z-spotlight)] flex justify-center px-4"
- style={{ bottom: "calc(5.5rem + var(--sai-bottom, 0px))" }}
- data-slot="shell-update-badge"
- >
- <Button
- type="button"
- variant="secondary"
- className="pointer-events-auto h-auto gap-2 rounded-2xl border border-border bg-card/95 px-3 py-2 text-sm shadow-[var(--shadow-win)] backdrop-blur"
- aria-label="New MSO version available — open Settings"
- onClick={() => openWindow("os-settings", "Settings")}
- >
- <ArrowDownToLine className="size-4 shrink-0 text-primary" />
- <span>New version available</span>
- <span className="rounded-md bg-primary/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-primary">
- Open
- </span>
- </Button>
- </div>
- );
-}
-
-export const updateShellBadgeFeature = defineFeature({
- id: "update-shell-badge",
- slots: { overlay: UpdateShellBadge },
-});
diff --git a/frontend/slices/os-settings/index.ts b/frontend/slices/os-settings/index.ts
index 81255414..8beb4428 100644
--- a/frontend/slices/os-settings/index.ts
+++ b/frontend/slices/os-settings/index.ts
@@ -1,6 +1,5 @@
import { Settings } from "lucide-react";
import type { AppDescriptor } from "@/features/appshell";
-export { updateShellBadgeFeature } from "./components/update-shell-badge";
// Barrel: the only thing the app layer imports. Exposes the app descriptor;
// the component itself is lazy-loaded via `load` so its bundle is deferred.
diff --git a/frontend/slices/os-shell/shell.manifest.ts b/frontend/slices/os-shell/shell.manifest.ts
index b9642288..46ba600c 100644
--- a/frontend/slices/os-shell/shell.manifest.ts
+++ b/frontend/slices/os-shell/shell.manifest.ts
@@ -17,7 +17,7 @@ import { createAppApp } from "@/features/create-app";
import { systemMonitorApp } from "@/features/system-monitor";
import { assistantApp } from "@/features/assistant";
import { hermesApp, nineRouterApp, openclawApp, orcaApp } from "@/features/managed-apps";
-import { osSettingsApp, updateShellBadgeFeature } from "@/features/os-settings";
+import { osSettingsApp } from "@/features/os-settings";
import { quicklinksApp } from "@/features/quicklinks";
import { docsApp } from "@/features/docs";
import { integrationsApp } from "@/features/integrations";
@@ -99,5 +99,6 @@ export const BUILTIN_APPS: AppDescriptor[] = [
// mounts into a named slot (overlay/rightPanel/notifications/topPill/
// controlCenter/today), so a feature absent from the array just doesn't render.
// Settings stays the `os-settings` app (its own slice). mso adds one consumer
-// features: theme-preset switcher in the menu-bar status cluster + shell update badge (UX-10).
-export const TOPSIDE_FEATURES: FeatureDescriptor[] = [...DEFAULT_FEATURES, serverConnectionStatusFeature, themeQuickPickerFeature, updateShellBadgeFeature];
+// feature: the theme-preset switcher in the menu-bar status cluster. Update
+// notices are not a shell feature; they live only in Settings.
+export const TOPSIDE_FEATURES: FeatureDescriptor[] = [...DEFAULT_FEATURES, serverConnectionStatusFeature, themeQuickPickerFeature];
diff --git a/scripts/e2e/shell-notices.mjs b/scripts/e2e/shell-notices.mjs
index 22bd1dbb..849d8c20 100644
--- a/scripts/e2e/shell-notices.mjs
+++ b/scripts/e2e/shell-notices.mjs
@@ -6,14 +6,22 @@ export async function shellNoticesJourney(page, fixture) {
for (const viewport of [{ width: 1280, height: 900 }, { width: 320, height: 844 }]) {
await page.setViewportSize(viewport);
await page.goto(fixture.base);
- await expect(page.locator('[data-slot="shell-update-badge"]')).toBeVisible();
+ const shell = page.locator("#main-content");
+ await expect(shell).toBeVisible();
+ // The dock-adjacent update badge is gone: one cue, inside Settings, no overlay
+ // over the interface. Asserting count 0 fails if anyone re-adds a floating badge.
+ await expect(shell.locator('[data-slot="shell-update-badge"]')).toHaveCount(0);
// MSO no longer renders its own install pill: installability stays a browser
// menu action, so even a fired `beforeinstallprompt` must render nothing here.
await page.evaluate(() => window.dispatchEvent(new Event("beforeinstallprompt", { cancelable: true })));
await expect(page.locator('[data-slot="pwa-install-prompt"]')).toHaveCount(0);
+ // The single remaining cue lives in Settings and still reads the release tag.
+ await page.goto(fixture.base + "/settings");
+ await expect(page.locator('[data-slot="settings-update-badge"]')).toBeVisible();
+ await expect(page.locator('[data-slot="shell-update-badge"]')).toHaveCount(0);
}
await page.unroute(status);
await page.setViewportSize({ width: 1280, height: 900 });
await page.goto(fixture.base + "/integrations");
- console.log("PASS the update notice stays visible and the removed install pill never renders at desktop and narrow mobile widths");
+ console.log("PASS no floating update badge or install pill at desktop and narrow mobile widths, and the Settings update badge still shows an available release");
}