From 3efda93208c04950d8514842244dfdeb20e6923b Mon Sep 17 00:00:00 2001 From: Simon Tenbusch Date: Fri, 3 Nov 2023 22:54:36 +0100 Subject: [PATCH 1/3] Check login before ask for notification permission Previously the user is interrupted on first login with a popup to allow notifications. Now the popup component checks if the user is logged in already an if not it will listen to input event. Resolves: #3243 --- src/components/notifications/notifications.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 2d11691e9..df015977d 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -3,6 +3,7 @@ import { playbackManager } from '../playback/playbackmanager'; import Events from '../../utils/events.ts'; import globalize from '../../scripts/globalize'; import { getItems } from '../../utils/jellyfin-apiclient/getItems.ts'; +import ServerConnections from '../../components/ServerConnections'; import NotificationIcon from './notificationicon.png'; @@ -16,9 +17,27 @@ function onOneDocumentClick() { Notification.requestPermission(); } } +function registerOneDocumentClickHandler() { + Events.off(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler); -document.addEventListener('click', onOneDocumentClick); -document.addEventListener('keydown', onOneDocumentClick); + document.addEventListener('click', onOneDocumentClick); + document.addEventListener('keydown', onOneDocumentClick); +} + +function initPermissionRequest() { + const apiClient = ServerConnections.currentApiClient(); + if (apiClient) { + apiClient.getCurrentUser() + .then(user => user && registerOneDocumentClickHandler()) + .catch(() => { + Events.on(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler); + }); + } else { + registerOneDocumentClickHandler(); + } +} + +initPermissionRequest(); let serviceWorkerRegistration; From 294e4c220c94975ea4371c79d9f99ade0c127492 Mon Sep 17 00:00:00 2001 From: SimonTen <34440207+SimonTen@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:40:24 +0100 Subject: [PATCH 2/3] remove useless null check --- src/components/notifications/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index df015977d..abdb7549f 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -28,7 +28,7 @@ function initPermissionRequest() { const apiClient = ServerConnections.currentApiClient(); if (apiClient) { apiClient.getCurrentUser() - .then(user => user && registerOneDocumentClickHandler()) + .then(user => registerOneDocumentClickHandler()) .catch(() => { Events.on(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler); }); From a78fd221580a820ca43347903f7b037f0d4a8bd5 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Thu, 18 Jan 2024 16:10:13 -0500 Subject: [PATCH 3/3] Fix whitespace and unused variable Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/components/notifications/notifications.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index abdb7549f..1e4d38b48 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -17,6 +17,7 @@ function onOneDocumentClick() { Notification.requestPermission(); } } + function registerOneDocumentClickHandler() { Events.off(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler); @@ -28,7 +29,7 @@ function initPermissionRequest() { const apiClient = ServerConnections.currentApiClient(); if (apiClient) { apiClient.getCurrentUser() - .then(user => registerOneDocumentClickHandler()) + .then(() => registerOneDocumentClickHandler()) .catch(() => { Events.on(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler); });