Skip to content

Commit

Permalink
Merge pull request #4935 from SimonTen/issues/3243
Browse files Browse the repository at this point in the history
Wait for login before ask for notification permission
  • Loading branch information
thornbill committed Jan 22, 2024
2 parents 62005df + a78fd22 commit 358b1f5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/notifications/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -17,8 +18,27 @@ function onOneDocumentClick() {
}
}

document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
function registerOneDocumentClickHandler() {
Events.off(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler);

document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
}

function initPermissionRequest() {
const apiClient = ServerConnections.currentApiClient();
if (apiClient) {
apiClient.getCurrentUser()
.then(() => registerOneDocumentClickHandler())
.catch(() => {
Events.on(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler);
});
} else {
registerOneDocumentClickHandler();
}
}

initPermissionRequest();

let serviceWorkerRegistration;

Expand Down

0 comments on commit 358b1f5

Please sign in to comment.