fix(pwa): suppress install dialog in in-app browsers

This commit is contained in:
2026-06-17 16:19:21 +08:00
parent 62468ffc6a
commit f39e7e0672
3 changed files with 2 additions and 10 deletions
@@ -14,6 +14,7 @@
*/
import { useEffect } from "react";
import { BrowserDetector } from "@/utils/browser-detect";
import { SpAsyncUtil } from "@/utils/storage";
import { pwaUtil } from "@/utils/pwa";
@@ -32,6 +33,7 @@ export function PwaInstallOverlay() {
// isInstalled() 检查 standalone display-mode(避免给已安装用户再弹)
if (!pwaUtil.isSupported()) return;
if (pwaUtil.isInstalled()) return;
if (BrowserDetector.isInAppBrowser()) return;
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
pwaUtil.prepareInstallPrompt();
-1
View File
@@ -2,5 +2,4 @@
* @file Automatically generated by barrelsby.
*/
export * from "./browser-detect";
export * from "./media-recorder";
@@ -29,13 +29,4 @@ export const BrowserDetector = {
return /WebView|; wv\)|FBAN|FBAV|MicroMessenger|Instagram|Line\//i.test(userAgent);
},
/** 当前是否以 PWA standalone 模式运行 */
isPWAStandalone(): boolean {
if (typeof window === "undefined") return false;
return (
window.matchMedia?.("(display-mode: standalone)").matches === true ||
// iOS Safari 旧版
(navigator as Navigator & { standalone?: boolean }).standalone === true
);
},
};