From 671181e8973ba8f294fdc5ec0112b99e8995eb00 Mon Sep 17 00:00:00 2001 From: Dominik Chrastecky Date: Sun, 4 Aug 2024 17:10:59 +0200 Subject: [PATCH] Add support for desktop-only and mobile-only notifications --- package.json | 1 + src/app/services/notification/notification.service.ts | 9 +++++++++ src/app/types/horde-notification.ts | 2 ++ yarn.lock | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/package.json b/package.json index 134b7d3..8dabd6a 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "image-in-browser": "^2.7.1", "lodash": "^4.17.21", "meta-png": "^1.0.6", + "ngx-device-detector": "^8.0.0", "ngx-tippy-wrapper": "^6.3.0", "ngx-toastr": "^18.0.0", "ngx-transloco-markup": "^6.0.0", diff --git a/src/app/services/notification/notification.service.ts b/src/app/services/notification/notification.service.ts index 5c0df31..fd1b1b1 100644 --- a/src/app/services/notification/notification.service.ts +++ b/src/app/services/notification/notification.service.ts @@ -8,6 +8,7 @@ import {SettingKey} from "../../types/setting-keys"; import {CacheService} from "../cache.service"; import {NotificationEnricher} from "./notification.enricher"; import {NOTIFICATION_ENRICHER} from "../../app.config"; +import {DeviceDetectorService} from "ngx-device-detector"; @Injectable({ providedIn: 'root' @@ -19,6 +20,7 @@ export class NotificationService { private readonly cache: CacheService, @Inject(NOTIFICATION_ENRICHER) private readonly enrichers: NotificationEnricher[], + private readonly deviceDetector: DeviceDetectorService, ) {} private async getNotifications(): Promise { @@ -156,6 +158,13 @@ export class NotificationService { } } + if (data.desktopOnly && !this.deviceDetector.isDesktop()) { + continue; + } + if (data.mobileOnly && !this.deviceDetector.isMobile() && !this.deviceDetector.isTablet()) { + continue; + } + result.push(notification); } diff --git a/src/app/types/horde-notification.ts b/src/app/types/horde-notification.ts index b6a0c34..e49a052 100644 --- a/src/app/types/horde-notification.ts +++ b/src/app/types/horde-notification.ts @@ -10,6 +10,8 @@ export interface HordeNgData { requiredVersion: string | string[]; onlyIfSeen: string; onlyIfNotSeen: string; + desktopOnly: boolean; + mobileOnly: boolean; } export interface HordeNotification { diff --git a/yarn.lock b/yarn.lock index 21ffe6e..790a945 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6282,6 +6282,13 @@ neo-async@^2.6.2: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== +ngx-device-detector@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/ngx-device-detector/-/ngx-device-detector-8.0.0.tgz#9d7523fbfc23f7655375ac5ef750e510e709464f" + integrity sha512-ik6EwUKnlN+xwoWHzyJp5+V+QRWYrmpTqAvRwa16xBnAVd7/i3jElN7MZjs/InwcYz7AW3XcSNeu+XRvtHgb9w== + dependencies: + tslib "^2.0.0" + ngx-tippy-wrapper@^6.3.0: version "6.3.0" resolved "https://registry.yarnpkg.com/ngx-tippy-wrapper/-/ngx-tippy-wrapper-6.3.0.tgz#981b165bcaddd08f28ac5daf20125ad7cbaa32c4"