aboutsummaryrefslogtreecommitdiff
path: root/src/routes/+layout.svelte
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-24 04:40:10 -0700
committerFuwn <[email protected]>2024-07-24 04:40:10 -0700
commit2efa0bcdc0c816076273fdf0ec07bb1c952c7c4e (patch)
treed0f27bf413f303a74821a69f86ac83cd6827036e /src/routes/+layout.svelte
parentfeat(proxy): drop headers (diff)
downloaddue.moe-2efa0bcdc0c816076273fdf0ec07bb1c952c7c4e.tar.xz
due.moe-2efa0bcdc0c816076273fdf0ec07bb1c952c7c4e.zip
feat(layout): browser notifications
Diffstat (limited to 'src/routes/+layout.svelte')
-rw-r--r--src/routes/+layout.svelte52
1 files changed, 25 insertions, 27 deletions
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index a34b24b1..d6575ded 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -111,36 +111,34 @@
});
if ($settings.displayAniListNotifications && data.user !== undefined) {
- if ('Notification' in window && navigator.serviceWorker) Notification.requestPermission();
-
- if (window.matchMedia('(display-mode: standalone)').matches) {
- notificationInterval = setInterval(async () => {
- try {
- const recentNotifications = await notifications(data.user.accessToken);
-
- if (
- recentNotifications &&
- recentNotifications.length > 0 &&
- recentNotifications[0].id > lastNotificationId &&
- new Date(recentNotifications[0].createdAt * 1000).getTime() + 30000 >
- new Date().getTime()
- ) {
- lastNotificationId = recentNotifications[0].id;
-
- if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
- navigator.serviceWorker.ready.then((registration) => {
- registration.showNotification('due.moe', {
- body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`,
- icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png'
+ if ('Notification' in window && navigator.serviceWorker)
+ if ((await Notification.requestPermission()) === 'granted')
+ notificationInterval = setInterval(async () => {
+ try {
+ const recentNotifications = await notifications(data.user.accessToken);
+
+ if (
+ recentNotifications &&
+ recentNotifications.length > 0 &&
+ recentNotifications[0].id > lastNotificationId &&
+ new Date(recentNotifications[0].createdAt * 1000).getTime() + 30000 >
+ new Date().getTime()
+ ) {
+ lastNotificationId = recentNotifications[0].id;
+
+ if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
+ navigator.serviceWorker.ready.then((registration) => {
+ registration.showNotification('due.moe', {
+ body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`,
+ icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png'
+ });
});
- });
+ }
}
+ } catch (error) {
+ console.error(error);
}
- } catch (error) {
- console.error(error);
- }
- }, 15000);
- }
+ }, 15000);
}
});