fix(pwa): suppress install dialog in in-app browsers
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
import { BrowserDetector } from "@/utils/browser-detect";
|
||||||
import { SpAsyncUtil } from "@/utils/storage";
|
import { SpAsyncUtil } from "@/utils/storage";
|
||||||
import { pwaUtil } from "@/utils/pwa";
|
import { pwaUtil } from "@/utils/pwa";
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ export function PwaInstallOverlay() {
|
|||||||
// isInstalled() 检查 standalone display-mode(避免给已安装用户再弹)
|
// isInstalled() 检查 standalone display-mode(避免给已安装用户再弹)
|
||||||
if (!pwaUtil.isSupported()) return;
|
if (!pwaUtil.isSupported()) return;
|
||||||
if (pwaUtil.isInstalled()) return;
|
if (pwaUtil.isInstalled()) return;
|
||||||
|
if (BrowserDetector.isInAppBrowser()) return;
|
||||||
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
|
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
|
||||||
pwaUtil.prepareInstallPrompt();
|
pwaUtil.prepareInstallPrompt();
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,4 @@
|
|||||||
* @file Automatically generated by barrelsby.
|
* @file Automatically generated by barrelsby.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./browser-detect";
|
|
||||||
export * from "./media-recorder";
|
export * from "./media-recorder";
|
||||||
|
|||||||
@@ -29,13 +29,4 @@ export const BrowserDetector = {
|
|||||||
return /WebView|; wv\)|FBAN|FBAV|MicroMessenger|Instagram|Line\//i.test(userAgent);
|
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
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user