fix(pwa): guide China users to Add to Home Screen (WebAPK needs Google)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-08-20 08:00:46 -05:00
parent 472cef16de
commit 565081678b

View File

@ -13,7 +13,6 @@ const DISMISS_KEY = "dylive_pwa_install_dismissed";
function isStandalone(): boolean {
if (typeof window === "undefined") return false;
if (window.matchMedia("(display-mode: standalone)").matches) return true;
// iOS Safari
return Boolean((navigator as Navigator & { standalone?: boolean }).standalone);
}
@ -42,13 +41,13 @@ export function PwaInstallBanner() {
setDeferred(e as BeforeInstallPromptEvent);
setVisible(true);
setIosHint(false);
setAndroidHint(false);
setAndroidHint(isAndroid);
setStatus("");
};
window.addEventListener("beforeinstallprompt", onBip);
const onInstalled = () => {
setStatus("已安装。若桌面没有图标,到手机「应用列表」找 LiveRadar,长按添加到桌面。");
setStatus("已添加。请看桌面是否出现 LiveRadar(可能带 Chrome 角标)。");
setVisible(true);
setDeferred(null);
};
@ -57,8 +56,7 @@ export function PwaInstallBanner() {
if (isIos && isSafari) {
setIosHint(true);
setVisible(true);
} else if (isAndroid && isChrome) {
// Chrome 可能不触发 beforeinstallprompt(已装过 / 策略限制),仍给出手动步骤
} else if (isAndroid) {
setAndroidHint(true);
setVisible(true);
}
@ -85,13 +83,16 @@ export function PwaInstallBanner() {
await deferred.prompt();
const choice = await deferred.userChoice;
if (choice.outcome === "accepted") {
setStatus("系统已确认安装。请到桌面或「应用列表」找 LiveRadar;没有的话长按应用图标 → 添加到桌面。");
setStatus(
"若桌面/应用列表仍没有:国内无 Google 时「安装应用」常会静默失败。请改用 Chrome ⋮ →「添加到主屏幕」。",
);
setAndroidHint(true);
} else {
setStatus("你取消了系统安装弹窗。也可手动:Chrome 右上角 ⋮ →「安装应用」或「添加到主屏幕」。");
setStatus("已取消。请用 Chrome 右上角 ⋮ →「添加到主屏幕」(不要点「安装应用」)。");
setAndroidHint(true);
}
} catch {
setStatus("系统安装弹窗失败。请用 Chrome 右上角 ⋮ →「安装应用」/「添加到主屏幕」。");
setStatus("安装弹窗失败。请用 Chrome ⋮ →「添加到主屏幕」。");
setAndroidHint(true);
} finally {
setDeferred(null);
@ -107,13 +108,13 @@ export function PwaInstallBanner() {
<Download className="h-4 w-4" />
</div>
<div className="min-w-0 flex-1">
<p className="text-sm font-medium text-slate-100">安装到主屏幕</p>
<p className="text-sm font-medium text-slate-100">添加到主屏幕</p>
<p className="mt-0.5 text-[11px] leading-relaxed text-slate-400">
{iosHint
? "Safari:点底部分享 →「添加到主屏幕」。"
: androidHint && !deferred
? "Chrome:右上角 ⋮ →「安装应用」或「添加到主屏幕」。装完若桌面没有,到应用列表找 LiveRadar。"
: "点安装后会弹出系统确认框;确认后图标可能在应用列表,不一定直接出现在桌面。"}
? "Safari:底部分享 →「添加到主屏幕」。"
: androidHint
? "国内网络请用:Chrome 右上角 ⋮ →「添加到主屏幕」。不要用「安装应用」(要连 Google,没翻墙常会装不上、桌面和应用列表都没有)。"
: "可选添加到主屏幕,方便手机快速打开。"}
</p>
{status ? (
<p className="mt-1.5 text-[11px] leading-relaxed text-amber-100/90">{status}</p>
@ -126,7 +127,7 @@ export function PwaInstallBanner() {
onClick={() => void install()}
className="rounded-lg bg-teal-500/20 px-3 py-1.5 text-xs text-teal-100 hover:bg-teal-500/30 disabled:opacity-50"
>
{busy ? "弹出中…" : "安装"}
{busy ? "弹出中…" : "尝试安装"}
</button>
) : null}
<button
@ -134,7 +135,7 @@ export function PwaInstallBanner() {
onClick={dismiss}
className="rounded-lg border border-white/10 px-3 py-1.5 text-xs text-slate-400"
>
以后再说
知道了
</button>
</div>
</div>