Fa arrivare le push ad app chiusa e rende diagnosticabile quando non arrivano.
Il testo della notifica viaggia ora cifrato dentro la push (aes128gcm, RFC
8188/8291) invece di essere recuperato dal service worker con una fetch al
risveglio. Era quella fetch a non chiudersi in tempo: ad app chiusa il browser
tiene vivo il worker pochi secondi, showNotification non veniva mai chiamata e
non compariva niente, mentre ad app aperta con la rete calda sembrava tutto a
posto. La POST porta anche Urgency: high, che chiede la consegna immediata
invece di far accumulare i messaggi fino al risveglio del dispositivo.
Cadono i pezzi che esistevano solo per rimediare al payload vuoto: la route
push-messaggio, la coda promemoria_push con la sua scadenza a 12 ore,
messaggioPalloniOggi() e il timeout nel worker. Tutti e tre i mittenti avevano
gia il testo pronto prima di inviare.
Il worker si aggiorna da solo all'avvio e a ogni ritorno in primo piano
(mantieniWorkerPushAggiornato): nella webapp installata quello vecchio puo
sopravvivere a lungo, e senza questo un dispositivo resterebbe fermo alla
versione che va a cercare il testo in rete.
Profilo -> Opzioni ha "Mandami una notifica di prova", visibile solo a notifiche
attive: manda una push a questo dispositivo e riporta stato HTTP, corpo della
risposta e se l'endpoint risulta davvero in push_subscriptions. Senza, "non
arriva" era cieco: ogni prova richiedeva un admin, un evento nello stato giusto
e una seconda persona, e la risposta del servizio push veniva buttata via.
inviaPush torna { stato, corpo } e logga il corpo sui rifiuti.
Dalle prove sul campo: a parita di server, iPhone installato da Home riceve ad
app chiusa. Su Android installato come webapp resta da verificare: il WebAPK e
un'app Android a se, con permesso notifiche (Android 13+) e voce batteria
distinti da quelli di Chrome. Annotato nei limiti noti.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+47
-1
@@ -1,7 +1,17 @@
|
||||
import { createFileRoute, Link } from "@tanstack/react-router";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Flame, Camera, Trash2, Bell, LogOut, ShieldCheck, Bug, Lightbulb } from "lucide-react";
|
||||
import {
|
||||
Flame,
|
||||
Camera,
|
||||
Trash2,
|
||||
Bell,
|
||||
BellRing,
|
||||
LogOut,
|
||||
ShieldCheck,
|
||||
Bug,
|
||||
Lightbulb,
|
||||
} from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Card, PageHeader, StatTile, TeamLogo } from "@/components/crapp/ui-bits";
|
||||
import { BarraSottosezioni } from "@/components/crapp/BarraSottosezioni";
|
||||
@@ -21,6 +31,7 @@ import { usePresenzeUltimoMese } from "@/lib/presenze-mese";
|
||||
import {
|
||||
attivaNotifiche,
|
||||
disattivaNotifiche,
|
||||
notificaDiProva,
|
||||
pushSupportato,
|
||||
statoNotifiche,
|
||||
} from "@/lib/push-client";
|
||||
@@ -72,6 +83,7 @@ function Profilo() {
|
||||
const [bust, setBust] = useState(0);
|
||||
const [notifiche, setNotifiche] = useState(false);
|
||||
const [inCorso, setInCorso] = useState(false);
|
||||
const [inProva, setInProva] = useState(false);
|
||||
const [supportate, setSupportate] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -103,6 +115,22 @@ function Profilo() {
|
||||
}
|
||||
}
|
||||
|
||||
async function provaNotifica() {
|
||||
if (inProva) return;
|
||||
setInProva(true);
|
||||
try {
|
||||
const esito = await notificaDiProva();
|
||||
if (!esito.nelDatabase) toast.error(esito.corpo);
|
||||
else if (esito.stato >= 200 && esito.stato < 300)
|
||||
toast.success("Push accettata dal servizio: verifica la notifica sul dispositivo");
|
||||
else toast.error(`Il servizio push ha risposto ${esito.stato}: ${esito.corpo}`);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "Prova non riuscita");
|
||||
} finally {
|
||||
setInProva(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await esci();
|
||||
@@ -271,6 +299,24 @@ function Profilo() {
|
||||
<Bell className="h-4 w-4" />
|
||||
</span>
|
||||
</button>
|
||||
{notifiche ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={provaNotifica}
|
||||
disabled={inProva}
|
||||
className="flex min-h-11 w-full items-center justify-between gap-3 px-4 py-3 text-left text-sm disabled:opacity-60"
|
||||
>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate">Mandami una notifica di prova</span>
|
||||
<span className="block text-xs text-muted-foreground">
|
||||
Invia subito una push a questo dispositivo
|
||||
</span>
|
||||
</span>
|
||||
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-xl bg-secondary text-muted-foreground">
|
||||
<BellRing className="h-4 w-4" />
|
||||
</span>
|
||||
</button>
|
||||
) : null}
|
||||
{admin ? (
|
||||
<Link
|
||||
to="/admin"
|
||||
|
||||
Reference in New Issue
Block a user