Improve blocked notification guidance
Some checks failed
ci / test (push) Has been cancelled

This commit is contained in:
VPN SaaS Dev
2026-05-16 14:04:56 +09:00
parent 069b0a66c0
commit 78749bb4fe
2 changed files with 63 additions and 7 deletions

View File

@@ -481,6 +481,7 @@
<section class="drawer-section hidden" id="notificationsSection"> <section class="drawer-section hidden" id="notificationsSection">
<h2>Уведомления</h2> <h2>Уведомления</h2>
<div class="tip-card" id="notificationStatus">Напомним о ТО, страховке и регулярном внесении пробега.</div> <div class="tip-card" id="notificationStatus">Напомним о ТО, страховке и регулярном внесении пробега.</div>
<div class="tip-card hidden" id="notificationHelp"></div>
<button type="button" class="wide-btn" id="enableNotificationsBtn">Включить уведомления</button> <button type="button" class="wide-btn" id="enableNotificationsBtn">Включить уведомления</button>
</section> </section>

View File

@@ -354,14 +354,71 @@ function updateNotificationStatus(message) {
if (node) node.textContent = t(message); if (node) node.textContent = t(message);
} }
async function enableNotifications() { function updateNotificationHelp(message = "") {
const node = document.querySelector("#notificationHelp");
if (!node) return;
node.textContent = message ? t(message) : "";
node.classList.toggle("hidden", !message);
}
function notificationBlockedMessage() {
const isIos = /iPhone|iPad|iPod/i.test(navigator.userAgent);
const isAndroid = /Android/i.test(navigator.userAgent);
if (isIos) {
return "Браузерные уведомления заблокированы. Открой настройки iOS: Settings → Notifications → браузер или Telegram, разреши уведомления и вернись сюда. Сервисные уведомления в Telegram продолжают работать.";
}
if (isAndroid) {
return "Браузерные уведомления заблокированы. Открой настройки сайта в браузере или настройки приложения Telegram/браузера на Android и разреши уведомления. Сервисные уведомления в Telegram продолжают работать.";
}
return "Браузерные уведомления заблокированы. Нажми на значок замка рядом с адресом сайта, открой Site settings / Настройки сайта и разреши Notifications. Сервисные уведомления в Telegram продолжают работать.";
}
function refreshNotificationUi() {
const button = document.querySelector("#enableNotificationsBtn");
if (!("Notification" in window)) { if (!("Notification" in window)) {
updateNotificationStatus("Браузер не поддерживает уведомления"); updateNotificationStatus("Браузер не поддерживает уведомления");
updateNotificationHelp("Важные события по СТО и заказ-нарядам все равно отправляются через Telegram-бота.");
if (button) button.disabled = true;
return;
}
if (Notification.permission === "granted") {
updateNotificationStatus("Уведомления включены");
updateNotificationHelp("");
if (button) {
button.disabled = false;
button.textContent = t("Проверить уведомления");
}
return;
}
if (Notification.permission === "denied") {
updateNotificationStatus("Уведомления запрещены в настройках браузера");
updateNotificationHelp(notificationBlockedMessage());
if (button) {
button.disabled = false;
button.textContent = t("Проверить снова");
}
return;
}
updateNotificationStatus("Напомним о ТО, страховке и регулярном внесении пробега.");
updateNotificationHelp("Если браузерный запрос будет отклонен, включить уведомления можно только вручную в настройках сайта.");
if (button) {
button.disabled = false;
button.textContent = t("Включить уведомления");
}
}
async function enableNotifications() {
if (!("Notification" in window)) {
refreshNotificationUi();
return;
}
if (Notification.permission === "denied") {
refreshNotificationUi();
return; return;
} }
const permission = await Notification.requestPermission(); const permission = await Notification.requestPermission();
if (permission !== "granted") { if (permission !== "granted") {
updateNotificationStatus("Уведомления запрещены в настройках браузера"); refreshNotificationUi();
return; return;
} }
const registration = state.serviceWorkerRegistration || (await navigator.serviceWorker?.ready); const registration = state.serviceWorkerRegistration || (await navigator.serviceWorker?.ready);
@@ -383,6 +440,8 @@ async function enableNotifications() {
}); });
} }
updateNotificationStatus("Уведомления включены"); updateNotificationStatus("Уведомления включены");
updateNotificationHelp("");
refreshNotificationUi();
} }
async function showDueReminders(registration) { async function showDueReminders(registration) {
@@ -2631,11 +2690,7 @@ async function openDrawerSection(sectionId, options = {}) {
document.querySelector("#currencySelect").value = state.user?.currency || "RUB"; document.querySelector("#currencySelect").value = state.user?.currency || "RUB";
} }
if (sectionId === "notificationsSection") { if (sectionId === "notificationsSection") {
updateNotificationStatus( refreshNotificationUi();
"Notification" in window && Notification.permission === "granted"
? "Уведомления включены"
: "Напомним о ТО, страховке и регулярном внесении пробега.",
);
} }
if (sectionId === "confirmationsSection") await loadConfirmations(); if (sectionId === "confirmationsSection") await loadConfirmations();
if (sectionId === "connectedServicesSection") await loadConnectedServices(); if (sectionId === "connectedServicesSection") await loadConnectedServices();