- Register the 8 new placeholder apps in DEMO_MOCK_UI so they're launchable and installable in the demo. - Demo bypasses the new-tab/tab-launch lists for demoable apps — they're served same-origin by the mock backend with no framing headers, so they render in the in-app session instead of opening broken localhost tabs. - Non-demoable apps now say 'Not available in demo' instead of 'No demo'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
/**
|
|
* Public-demo helpers.
|
|
*
|
|
* The demo build (VITE_DEMO=1) replays the intro/onboarding on each visit, but
|
|
* only once per calendar day per browser — tracked in localStorage so it
|
|
* survives the short-lived backend session. Also exposes the shared demo
|
|
* credentials shown on the login screen.
|
|
*/
|
|
|
|
export const IS_DEMO =
|
|
import.meta.env.VITE_DEMO === '1' || import.meta.env.VITE_DEMO === 'true'
|
|
|
|
/** Memorable shared password for the public demo (must match the mock backend). */
|
|
export const DEMO_PASSWORD = 'entertoexit'
|
|
|
|
const INTRO_DATE_KEY = 'demo_intro_date'
|
|
|
|
function todayKey(): string {
|
|
// Local calendar day, e.g. "2026-06-22".
|
|
const d = new Date()
|
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
}
|
|
|
|
/** True if this browser already watched the intro earlier today. */
|
|
export function demoIntroSeenToday(): boolean {
|
|
try {
|
|
return localStorage.getItem(INTRO_DATE_KEY) === todayKey()
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
/** Record that the intro has been seen today, so it won't replay until tomorrow. */
|
|
export function markDemoIntroSeen(): void {
|
|
try {
|
|
localStorage.setItem(INTRO_DATE_KEY, todayKey())
|
|
} catch {
|
|
/* ignore (private mode / storage disabled) */
|
|
}
|
|
}
|
|
|
|
/** Forget today's "seen" marker so the intro plays again (e.g. "Replay Intro"). */
|
|
export function clearDemoIntroSeen(): void {
|
|
try {
|
|
localStorage.removeItem(INTRO_DATE_KEY)
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
// ── Demoable apps ───────────────────────────────────────────────────────────
|
|
// Only these apps actually do something in the demo (a mock UI or a real
|
|
// external site). Everything else shows "No demo" on a disabled install button
|
|
// and is not launchable.
|
|
const DEMO_EXTERNAL_URLS: Record<string, string> = {}
|
|
|
|
// Apps loaded in the in-app iframe via a same-origin path. IndeeHub and Mempool
|
|
// are reverse-proxied by nginx (X-Frame-Options/CSP stripped + asset paths
|
|
// rewritten) so the frame-busting real sites can be embedded.
|
|
const DEMO_MOCK_UI: Record<string, string> = {
|
|
indeedhub: '/app/indeedhub/',
|
|
mempool: '/app/mempool/',
|
|
'mempool-web': '/app/mempool/',
|
|
'bitcoin-knots': '/app/bitcoin-knots/',
|
|
'bitcoin-core': '/app/bitcoin-core/',
|
|
bitcoin: '/app/bitcoin-core/',
|
|
'bitcoin-ui': '/app/bitcoin-ui/',
|
|
electrs: '/app/electrumx/',
|
|
electrumx: '/app/electrumx/',
|
|
'archy-electrs-ui': '/app/electrumx/',
|
|
lnd: '/app/lnd/',
|
|
'lnd-ui': '/app/lnd/',
|
|
'archy-lnd-ui': '/app/lnd/',
|
|
thunderhub: '/app/lnd/',
|
|
fedimint: '/app/fedimint/',
|
|
fedimintd: '/app/fedimint/',
|
|
filebrowser: '/app/filebrowser/',
|
|
// Static placeholder dashboards served by the mock backend (DEMO_APP_PAGES).
|
|
'btcpay-server': '/app/btcpay-server/',
|
|
grafana: '/app/grafana/',
|
|
nextcloud: '/app/nextcloud/',
|
|
jellyfin: '/app/jellyfin/',
|
|
vaultwarden: '/app/vaultwarden/',
|
|
'nostr-rs-relay': '/app/nostr-rs-relay/',
|
|
searxng: '/app/searxng/',
|
|
'uptime-kuma': '/app/uptime-kuma/',
|
|
}
|
|
|
|
/**
|
|
* Whether a demo app opens in a new tab. Nothing does — IndeeHub and Mempool
|
|
* both load their real site directly in the in-app iframe.
|
|
*/
|
|
export function isDemoExternal(_appId: string): boolean {
|
|
return false
|
|
}
|
|
|
|
/** Can this app be launched/installed in the demo? */
|
|
export function isDemoApp(appId: string): boolean {
|
|
return appId in DEMO_EXTERNAL_URLS || appId in DEMO_MOCK_UI
|
|
}
|
|
|
|
/** Resolve the demo launch URL for an app, or null if it isn't demoable. */
|
|
export function demoAppUrl(appId: string): string | null {
|
|
return DEMO_EXTERNAL_URLS[appId] ?? DEMO_MOCK_UI[appId] ?? null
|
|
}
|