Skip to content

Commit

Permalink
Add support for desktop-only and mobile-only notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Aug 4, 2024
1 parent 18b3b73 commit 671181e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/app/services/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<HordeNotification[]> {
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/types/horde-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface HordeNgData {
requiredVersion: string | string[];
onlyIfSeen: string;
onlyIfNotSeen: string;
desktopOnly: boolean;
mobileOnly: boolean;
}

export interface HordeNotification {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 671181e

Please sign in to comment.