From b59a2101b460200e4276a05f9b8cb4ae7a2e9b62 Mon Sep 17 00:00:00 2001 From: rupak Date: Fri, 30 Jan 2026 02:19:35 +0545 Subject: Add option to enable notifications (#8458) Closes https://github.com/FreshRSS/FreshRSS/issues/7330 - Default behavior is same - Added FreshRSS_Context::userConf()->html5_disable_notif so that, it determines weather user wants notification. (will not show any even it has permission) (i want default false so disable, so old configs get proper default values) - Added button such that checking it makes it request permission too image - test notification actually happening (how can i trigger it, do i have to wait it), this code fixes permissions. --- p/scripts/main.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 0ff9e609c..3241c127f 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1965,23 +1965,26 @@ function init_notifications() { // // -let notifs_html5_permission = 'denied'; +context.notifs_html5_permission = 'denied'; function notifs_html5_is_supported() { return window.Notification !== undefined; } -function notifs_html5_ask_permission() { +async function notifs_html5_ask_permission() { try { - window.Notification.requestPermission(function () { - notifs_html5_permission = window.Notification.permission; - }); + context.notifs_html5_permission = await window.Notification.requestPermission(); } catch (e) { + // User denied + context.notifs_html5_permission = 'denied'; } } function notifs_html5_show(nb, nb_new) { - if (notifs_html5_permission !== 'granted') { + if (!context.html5_enable_notif) { + return; // from config + } + if (context.notifs_html5_permission !== 'granted') { return; } @@ -2013,8 +2016,16 @@ function init_notifs_html5() { if (!notifs_html5_is_supported()) { return; } - - notifs_html5_permission = notifs_html5_ask_permission(); + // from config, 1st run this should be true + if (!context.html5_enable_notif) { + return; + } + context.notifs_html5_permission = Notification.permission; + // Only ask if the user hasn’t answered yet + // otherwise they need to ask from settings > display + if (context.notifs_html5_permission === 'default') { + notifs_html5_ask_permission(); + } } // -- cgit v1.2.3