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
This commit is contained in:
Simon Tenbusch 2023-11-03 22:54:36 +01:00 committed by Bill Thornton
parent bb77009f44
commit 3efda93208

View File

@ -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;