import { useState, useEffect, ReactNode } from "react"; import { Terminal } from "lucide-react"; import { useAccountSync } from "@/hooks/useAccountSync"; import { useRelayListCacheSync } from "@/hooks/useRelayListCacheSync"; import { useRelayState } from "@/hooks/useRelayState"; import relayStateManager from "@/services/relay-state-manager"; import { TabBar } from "../TabBar"; import CommandLauncher from "../CommandLauncher"; import { GlobalAuthPrompt } from "../GlobalAuthPrompt"; import { SpellbookDropdown } from "../SpellbookDropdown"; import UserMenu from "../nostr/user-menu"; import { AppShellContext } from "./AppShellContext"; interface AppShellProps { children: ReactNode; } export function AppShell({ children }: AppShellProps) { const [commandLauncherOpen, setCommandLauncherOpen] = useState(false); // Sync active account and fetch relay lists useAccountSync(); // Auto-cache kind:10002 relay lists from EventStore to Dexie useRelayListCacheSync(); // Initialize global relay state manager useEffect(() => { relayStateManager.initialize().catch((err) => { console.error("Failed to initialize relay state manager:", err); }); }, []); // Sync relay state with Jotai useRelayState(); // Keyboard shortcut: Cmd/Ctrl+K useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === "k") { e.preventDefault(); setCommandLauncherOpen((open) => !open); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, []); const openCommandLauncher = () => setCommandLauncherOpen(true); return (
{children}
); }