"use client"; // THE BROWSER'S DISPLAYERS (demo epic D4): `useDisplay()` gives a client // component the same `displayPath` / `displayText` pair the server has // (lib/privacy/privacy-server.ts), bound to the rules the root layout hands // — `clientPrivacyRules()`, which never holds a rule from // the operator's private files (those apply only where a page renders on the // server). // // No provider, no rules: the identity. The root layouts render the provider // ONLY while settings.privacy is active, so a page with the block absent // carries no extra element and no extra prop. // // KEEPING THE RULES CURRENT (review round 1, S8a). A client-side navigation // does not re-render the root layout, so a changed `privacy` block would // leave client panels on the old rules. While the provider is mounted, a // navigation asks the router to refresh (at most once every REFRESH_MS), // which re-renders the layout with the rules as they are now — a change, or // privacy turned OFF, reaches the client panels on the next page. Turning it // ON from off reaches them at the next full load (in the editor, also at its // auto-refresh tick, which re-renders the layout too). // // The rules here CARRY the values they hide (the home dir, the hostname, the // user name, the volume UUIDs and roots, every alias's left side): they are // in the page's script payload, which view-source shows. The audit reads only // what is drawn. SETTINGS.md says so too. import { createContext, useContext, useEffect, useMemo, useRef, type ReactNode } from "react"; import { usePathname, useRouter } from "next/navigation"; import { displayersOf, IDENTITY, type PrivacyRules } from "../lib/privacy/display"; const PrivacyContext = createContext(null); export const REFRESH_MS = 10_000; export function PrivacyProvider({ rules, children }: { rules: PrivacyRules; children: ReactNode }) { const router = useRouter(); const pathname = usePathname(); const first = useRef(true); const last = useRef(0); useEffect(() => { if (first.current) { first.current = false; last.current = Date.now(); return; } if (Date.now() - last.current < REFRESH_MS) return; last.current = Date.now(); router.refresh(); }, [pathname, router]); return {children}; } export function useDisplay(): typeof IDENTITY { const rules = useContext(PrivacyContext); return useMemo(() => displayersOf(rules), [rules]); }