diff --git a/apps/ai-game-creator-shell/src/App.tsx b/apps/ai-game-creator-shell/src/App.tsx index 8961828b7..2ab271d84 100644 --- a/apps/ai-game-creator-shell/src/App.tsx +++ b/apps/ai-game-creator-shell/src/App.tsx @@ -2176,6 +2176,8 @@ export function WorkspaceLauncher({ >([]); const [showcaseStatus, setShowcaseStatus] = useState('正在读取灵感'); const homeAttachmentInputRef = useRef(null); + const accountMenuRef = useRef(null); + const helpMenuRef = useRef(null); const launcherAgentChatAgents = deriveAgentStatusCards(seedManifest, null); const [agentChatProjectPath, setAgentChatProjectPath] = useState(defaultProjectPath); @@ -2268,6 +2270,44 @@ export function WorkspaceLauncher({ void loadWalletLedger(); }, [walletPanelOpen, walletLedgerStatus]); + useEffect(() => { + function closeSidebarMenusIfOutside(target: EventTarget | null) { + if (!(target instanceof Node)) { + return; + } + if ( + accountMenuRef.current?.contains(target) || + helpMenuRef.current?.contains(target) + ) { + return; + } + setAccountMenuOpen(false); + setHelpMenuOpen(false); + } + + function handlePointerDown(event: PointerEvent) { + closeSidebarMenusIfOutside(event.target); + } + + function handleFocusIn(event: FocusEvent) { + closeSidebarMenusIfOutside(event.target); + } + + function handleWindowBlur() { + setAccountMenuOpen(false); + setHelpMenuOpen(false); + } + + document.addEventListener('pointerdown', handlePointerDown); + document.addEventListener('focusin', handleFocusIn); + window.addEventListener('blur', handleWindowBlur); + return () => { + document.removeEventListener('pointerdown', handlePointerDown); + document.removeEventListener('focusin', handleFocusIn); + window.removeEventListener('blur', handleWindowBlur); + }; + }, []); + function validateProjectPath(nextProjectPath: string) { const trimmedProjectPath = nextProjectPath.trim(); if (!trimmedProjectPath || !isAbsoluteProjectPath(trimmedProjectPath)) { @@ -2993,7 +3033,7 @@ export function WorkspaceLauncher({
-
+
-
+