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:
parent
bb77009f44
commit
3efda93208
1 changed files with 21 additions and 2 deletions
|
@ -3,6 +3,7 @@ import { playbackManager } from '../playback/playbackmanager';
|
||||||
import Events from '../../utils/events.ts';
|
import Events from '../../utils/events.ts';
|
||||||
import globalize from '../../scripts/globalize';
|
import globalize from '../../scripts/globalize';
|
||||||
import { getItems } from '../../utils/jellyfin-apiclient/getItems.ts';
|
import { getItems } from '../../utils/jellyfin-apiclient/getItems.ts';
|
||||||
|
import ServerConnections from '../../components/ServerConnections';
|
||||||
|
|
||||||
import NotificationIcon from './notificationicon.png';
|
import NotificationIcon from './notificationicon.png';
|
||||||
|
|
||||||
|
@ -16,9 +17,27 @@ function onOneDocumentClick() {
|
||||||
Notification.requestPermission();
|
Notification.requestPermission();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function registerOneDocumentClickHandler() {
|
||||||
|
Events.off(ServerConnections, 'localusersignedin', registerOneDocumentClickHandler);
|
||||||
|
|
||||||
document.addEventListener('click', onOneDocumentClick);
|
document.addEventListener('click', onOneDocumentClick);
|
||||||
document.addEventListener('keydown', 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;
|
let serviceWorkerRegistration;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue