feat(pwa): remove install prompt
All checks were successful
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
/ build-web (push) Successful in 5m40s
/ build-desktop (linux) (push) Successful in 10m33s
/ build-mobile (push) Successful in 23m6s
/ release (push) Successful in 2m15s
All checks were successful
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
/ build-web (push) Successful in 5m40s
/ build-desktop (linux) (push) Successful in 10m33s
/ build-mobile (push) Successful in 23m6s
/ release (push) Successful in 2m15s
This commit is contained in:
parent
7b36218ffa
commit
caa7d65b84
3 changed files with 13 additions and 60 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
"entry": [
|
"entry": [
|
||||||
"src/index.{ts,tsx,js,jsx}",
|
"src/index.{ts,tsx,js,jsx}",
|
||||||
"src/main.{ts,tsx,js,jsx}",
|
"src/main.{ts,tsx,js,jsx}",
|
||||||
|
"apps/pwa/src/serviceWorker.ts",
|
||||||
"apps/tauri/render-version.ts",
|
"apps/tauri/render-version.ts",
|
||||||
"packages/**/*.test.ts"
|
"packages/**/*.test.ts"
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
import { setDatabaseEntry } from "@tensamin/shared/indexedDb";
|
import { setDatabaseEntry } from "@tensamin/shared/indexedDb";
|
||||||
|
|
@ -6,11 +6,6 @@ import { isTauri } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
|
|
||||||
type BeforeInstallPromptEvent = Event & {
|
|
||||||
prompt: () => Promise<void>;
|
|
||||||
userChoice: Promise<{ outcome: "accepted" | "dismissed" }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const launchedFiles: File[] = [];
|
const launchedFiles: File[] = [];
|
||||||
const fileListeners = new Set<(file: File) => void>();
|
const fileListeners = new Set<(file: File) => void>();
|
||||||
|
|
||||||
|
|
@ -66,9 +61,6 @@ async function enablePush() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PwaRuntime() {
|
export default function PwaRuntime() {
|
||||||
const [installPrompt, setInstallPrompt] =
|
|
||||||
useState<BeforeInstallPromptEvent | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
isTauri() ||
|
isTauri() ||
|
||||||
|
|
@ -129,16 +121,6 @@ export default function PwaRuntime() {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleInstallPrompt = (event: Event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
setInstallPrompt(event as BeforeInstallPromptEvent);
|
|
||||||
};
|
|
||||||
window.addEventListener("beforeinstallprompt", handleInstallPrompt);
|
|
||||||
return () =>
|
|
||||||
window.removeEventListener("beforeinstallprompt", handleInstallPrompt);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const launchQueue = (
|
const launchQueue = (
|
||||||
window as Window & {
|
window as Window & {
|
||||||
|
|
@ -158,39 +140,6 @@ export default function PwaRuntime() {
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!installPrompt) return;
|
|
||||||
toast("Install Tensamin for a native app experience", {
|
|
||||||
duration: Infinity,
|
|
||||||
action: {
|
|
||||||
label: "Install",
|
|
||||||
onClick: () => {
|
|
||||||
void installPrompt.prompt().then(() => installPrompt.userChoice);
|
|
||||||
setInstallPrompt(null);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}, [installPrompt]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const isAppleMobile = /iPad|iPhone|iPod/.test(navigator.userAgent);
|
|
||||||
if (
|
|
||||||
isTauri() ||
|
|
||||||
!isAppleMobile ||
|
|
||||||
isStandalone() ||
|
|
||||||
localStorage.getItem("pwa-ios-install-hint")
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
localStorage.setItem("pwa-ios-install-hint", "shown");
|
|
||||||
toast(
|
|
||||||
"Install Tensamin from Safari's Share menu to enable background notifications.",
|
|
||||||
{
|
|
||||||
duration: 12_000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!isStandalone() ||
|
!isStandalone() ||
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,22 @@ function isPushPayload(value: unknown): value is PushPayload {
|
||||||
const message = payload.message as
|
const message = payload.message as
|
||||||
Partial<PushPayload["message"]> | undefined;
|
Partial<PushPayload["message"]> | undefined;
|
||||||
const secret = payload.secret as Partial<PushPayload["secret"]> | undefined;
|
const secret = payload.secret as Partial<PushPayload["secret"]> | undefined;
|
||||||
|
const stringValues = [
|
||||||
|
payload.sender,
|
||||||
|
message?.content,
|
||||||
|
secret?.chatId,
|
||||||
|
secret?.secretId,
|
||||||
|
secret?.encryptedSecret,
|
||||||
|
secret?.kemCiphertext,
|
||||||
|
secret?.wrappingScheme,
|
||||||
|
];
|
||||||
return (
|
return (
|
||||||
payload.version === 1 &&
|
payload.version === 1 &&
|
||||||
typeof payload.senderId === "number" &&
|
typeof payload.senderId === "number" &&
|
||||||
Number.isSafeInteger(payload.senderId) &&
|
Number.isSafeInteger(payload.senderId) &&
|
||||||
payload.senderId > 0 &&
|
payload.senderId > 0 &&
|
||||||
typeof payload.sender === "string" &&
|
typeof secret?.version === "number" &&
|
||||||
typeof message?.content === "string" &&
|
stringValues.every((item) => typeof item === "string")
|
||||||
typeof secret?.chatId === "string" &&
|
|
||||||
typeof secret.secretId === "string" &&
|
|
||||||
typeof secret.version === "number" &&
|
|
||||||
typeof secret.encryptedSecret === "string" &&
|
|
||||||
typeof secret.kemCiphertext === "string" &&
|
|
||||||
typeof secret.wrappingScheme === "string"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue