Improve handling of notification permission prompts

Update notification permission logic to differentiate between denied and dismissed states, and adjust locale messages accordingly.
This commit is contained in:
Riyadh
2026-05-17 17:21:18 +00:00
parent bf5bfa29c4
commit e44c9a8976
3 changed files with 12 additions and 1 deletions
@@ -25,6 +25,7 @@ export type EnableReason =
| "unsupported"
| "unsupported_ios_safari"
| "permission_denied"
| "permission_dismissed"
| "vapid_unavailable"
| "subscribe_failed"
| "server_rejected";
@@ -148,7 +149,15 @@ export function usePushSubscription() {
const perm = await Notification.requestPermission();
if (perm !== "granted") {
setStatus(perm === "denied" ? "denied" : "default");
return { ok: false, reason: "permission_denied" };
// Distinguish a hard "blocked" decision from the user just
// dismissing the prompt without choosing — the messages need
// to differ so we don't tell users to "unblock" when they
// simply haven't decided yet.
return {
ok: false,
reason:
perm === "denied" ? "permission_denied" : "permission_dismissed",
};
}
const reg = await getRegistration();
if (!reg) return { ok: false, reason: "subscribe_failed" };
+1
View File
@@ -240,6 +240,7 @@
"unsupported": "هذا المتصفح لا يدعم إشعارات شاشة القفل.",
"unsupported_ios_safari": "على الآيفون/الآيباد، افتح Tx من أيقونة الشاشة الرئيسية أولاً (مشاركة → إضافة إلى الشاشة الرئيسية)، ثم فعّل الإشعارات من داخل التطبيق.",
"permission_denied": "أذِن المتصفح للإشعارات مرفوض. افتح إعدادات الجهاز ← Tx وفعّل الإشعارات يدوياً.",
"permission_dismissed": "لم يتم منح الإذن بعد. اضغط \"تفعيل\" مرة أخرى واختر \"السماح\" في نافذة المتصفح.",
"vapid_unavailable": "تعذّر الاتصال بخادم الإشعارات. تأكّد من اتصالك ثم حاول مرة أخرى.",
"subscribe_failed": "تعذّر تسجيل الجهاز لاستقبال الإشعارات. حاول مرة أخرى.",
"server_rejected": "رفض الخادم تسجيل هذا الجهاز. حاول مرة أخرى أو أعد تسجيل الدخول."
+1
View File
@@ -246,6 +246,7 @@
"unsupported": "This browser does not support lock-screen notifications.",
"unsupported_ios_safari": "On iPhone/iPad, open Tx OS from its Home Screen icon first (Share → Add to Home Screen), then enable notifications from inside the app.",
"permission_denied": "Notification permission is blocked. Open Settings → Tx OS on your device and enable notifications manually.",
"permission_dismissed": "Permission wasn't granted yet. Tap \"Enable\" again and choose \"Allow\" in the browser prompt.",
"vapid_unavailable": "Could not reach the notifications server. Check your connection and try again.",
"subscribe_failed": "Could not register this device for notifications. Try again.",
"server_rejected": "The server refused to register this device. Try again or sign in again."