diff --git a/src/app/chat/chat-screen.tsx b/src/app/chat/chat-screen.tsx
index 8a840d4e..3695b75d 100644
--- a/src/app/chat/chat-screen.tsx
+++ b/src/app/chat/chat-screen.tsx
@@ -67,6 +67,7 @@ export function ChatScreen() {
historyLoaded: state.historyLoaded,
loginStatus: authState.loginStatus,
});
+ const shouldShowPwaInstall = state.historyLoaded && state.messages.length >= 10;
const externalBrowserPromptShownRef = useRef(false);
@@ -181,8 +182,8 @@ export function ChatScreen() {
{/* 浏览器提示(应用内浏览器检测) */}
- {/* PWA 安装提示触发器(无可见 UI,3.5s 后弹 dialog) */}
-
+ {/* PWA 安装提示触发器(聊天消息数量达到阈值后才允许弹出) */}
+
{
+ if (!enabled) return;
+
let mounted = true;
+ let timer: number | undefined;
const init = async () => {
// const isDev = AppEnvUtil.isDevelopment();
@@ -34,9 +44,11 @@ export function PwaInstallOverlay() {
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
pwaUtil.prepareInstallPrompt();
- // 开发环境 1s 后弹(快);生产环境 3.5s 后弹(让用户先看到聊天内容)
- const delay = isDev ? 1000 : 3500;
- setTimeout(() => {
+ // 达到聊天数量阈值后稍作停顿,避免弹窗与消息刷新挤在同一瞬间。
+ const delay = isDev
+ ? DEVELOPMENT_DIALOG_DELAY_MS
+ : PRODUCTION_DIALOG_DELAY_MS;
+ timer = window.setTimeout(() => {
if (!mounted) return;
showPwaDialog();
}, delay);
@@ -45,8 +57,9 @@ export function PwaInstallOverlay() {
void init();
return () => {
mounted = false;
+ if (timer !== undefined) window.clearTimeout(timer);
};
- }, []);
+ }, [enabled]);
return ;
}