export type AppEvents = { "player:open": { name: string }; }; export function dispatchAppEvent( name: K, detail: AppEvents[K] ): void { if (typeof window === "undefined") return; window.dispatchEvent(new CustomEvent(name, { detail })); } export function onAppEvent( name: K, handler: (detail: AppEvents[K]) => void ): () => void { if (typeof window === "undefined") return () => {}; const listener = (e: Event) => handler((e as CustomEvent).detail); window.addEventListener(name, listener); return () => window.removeEventListener(name, listener); }