From 0659e52d29c702f0d9e59feecce385a74e8accff Mon Sep 17 00:00:00 2001 From: chenhang Date: Thu, 9 Jul 2026 14:25:20 +0800 Subject: [PATCH] refactor(chat): launch external browser without dialog --- src/app/chat/chat-screen.tsx | 9 +-- .../external-browser-dialog.module.css | 79 ------------------- .../components/external-browser-dialog.tsx | 51 ------------ src/app/chat/components/index.ts | 1 - .../chat/hooks/use-external-browser-prompt.ts | 43 +++++----- 5 files changed, 19 insertions(+), 164 deletions(-) delete mode 100644 src/app/chat/components/external-browser-dialog.module.css delete mode 100644 src/app/chat/components/external-browser-dialog.tsx diff --git a/src/app/chat/chat-screen.tsx b/src/app/chat/chat-screen.tsx index edc4a3b6..8ccb4629 100644 --- a/src/app/chat/chat-screen.tsx +++ b/src/app/chat/chat-screen.tsx @@ -17,7 +17,6 @@ import { ChatInputBar, ChatInsufficientCreditsBanner, ChatUnlockDialogs, - ExternalBrowserDialog, FirstRechargeOfferBanner, FullscreenImageViewer, PwaInstallOverlay, @@ -92,7 +91,7 @@ export function ChatScreen() { loginStatus: authState.loginStatus, }); const shouldShowPwaInstall = state.historyLoaded && state.messages.length >= 10; - const externalBrowserPrompt = useExternalBrowserPrompt({ + useExternalBrowserPrompt({ hasInitialized: authState.hasInitialized, isLoading: authState.isLoading, loginStatus: authState.loginStatus, @@ -198,12 +197,6 @@ export function ChatScreen() { {/* PWA 安装提示触发器(聊天消息数量达到阈值后才允许弹出) */} - void externalBrowserPrompt.confirm()} - /> - void; - onConfirm: () => void; -} - -export function ExternalBrowserDialog({ - open, - onClose, - onConfirm, -}: ExternalBrowserDialogProps) { - if (!open) return null; - - return ( -
-
-

- Open in browser -

-

- Sync your Facebook profile to an external browser for the best chat experience. -

-
- - -
-
-
- ); -} diff --git a/src/app/chat/components/index.ts b/src/app/chat/components/index.ts index e8da0746..2f1133b4 100644 --- a/src/app/chat/components/index.ts +++ b/src/app/chat/components/index.ts @@ -12,7 +12,6 @@ export * from "./chat-input-text-field"; export * from "./chat-send-button"; export * from "./chat-unlock-dialogs"; export * from "./date-header"; -export * from "./external-browser-dialog"; export * from "./first-recharge-offer-banner"; export * from "./fullscreen-image-viewer"; export * from "./history-unlock-dialog"; diff --git a/src/app/chat/hooks/use-external-browser-prompt.ts b/src/app/chat/hooks/use-external-browser-prompt.ts index faafb2a2..3c6ab633 100644 --- a/src/app/chat/hooks/use-external-browser-prompt.ts +++ b/src/app/chat/hooks/use-external-browser-prompt.ts @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useEffect, useRef } from "react"; import { openChatInExternalBrowser, @@ -15,18 +15,11 @@ import { const EXTERNAL_BROWSER_PROMPT_DELAY_MS = 3000; -export interface ExternalBrowserPromptController { - open: boolean; - close: () => void; - confirm: () => Promise; -} - export function useExternalBrowserPrompt({ hasInitialized, isLoading, loginStatus, -}: ExternalBrowserPromptState): ExternalBrowserPromptController { - const [open, setOpen] = useState(false); +}: ExternalBrowserPromptState): void { const promptShownRef = useRef(false); useEffect(() => { @@ -52,8 +45,22 @@ export function useExternalBrowserPrompt({ promptShownRef.current = true; timer = window.setTimeout(() => { if (!mounted) return; - setOpen(true); - void recordExternalBrowserPromptShown(eligibility.today); + void (async () => { + try { + await recordExternalBrowserPromptShown(eligibility.today); + } catch (error) { + console.warn( + "[chat] Failed to record external browser auto launch", + error, + ); + } + if (!mounted) return; + try { + await openChatInExternalBrowser(); + } catch (error) { + console.warn("[chat] Failed to open external browser", error); + } + })(); }, EXTERNAL_BROWSER_PROMPT_DELAY_MS); }; @@ -65,18 +72,4 @@ export function useExternalBrowserPrompt({ }; }, [hasInitialized, isLoading, loginStatus]); - const close = useCallback(() => { - setOpen(false); - }, []); - - const confirm = useCallback(async () => { - setOpen(false); - await openChatInExternalBrowser(); - }, []); - - return { - open, - close, - confirm, - }; }