fix(pwa): tighten install support detection

This commit is contained in:
2026-07-04 11:18:01 +08:00
parent f470119a1b
commit 82ac9e86a5
5 changed files with 301 additions and 73 deletions
+12 -7
View File
@@ -43,22 +43,27 @@ export function SidebarScreen() {
]);
useEffect(() => {
const updateInstallEntryVisibility = () => {
setCanShowInstallApp(pwaUtil.canShowInstallEntry());
};
pwaUtil.prepareInstallPrompt();
const timer = window.setTimeout(() => {
setCanShowInstallApp(pwaUtil.isSupported() && !pwaUtil.isInstalled());
}, 0);
updateInstallEntryVisibility();
const unsubscribe = pwaUtil.subscribe(updateInstallEntryVisibility);
return () => {
window.clearTimeout(timer);
unsubscribe();
};
}, []);
const handleInstallAppClick = async () => {
pwaUtil.prepareInstallPrompt();
const result = await pwaUtil.install();
if (result === "accepted" || pwaUtil.isInstalled()) {
setCanShowInstallApp(false);
}
setCanShowInstallApp(
result !== "accepted" &&
!pwaUtil.isInstalled() &&
pwaUtil.canShowInstallEntry(),
);
};
const handleLogoutClick = () => {