1
0
mirror of https://github.com/bitwarden/browser synced 2026-03-01 11:01:17 +00:00

feat(notification-processing): [PM-19877] System Notification Implementation - Giving up on safari. Getting the code ready for review now.

This commit is contained in:
Patrick Pimentel
2025-07-21 12:41:23 -04:00
parent b269eaed0b
commit 50621218d4
5 changed files with 71 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ import { LogoutReason } from "@bitwarden/auth/common";
import { ActionsService } from "@bitwarden/common/platform/actions";
import {
ButtonActions,
ButtonLocation,
SystemNotificationEvent,
SystemNotificationsService,
} from "@bitwarden/common/platform/notifications/system-notifications-service";
@@ -66,12 +67,12 @@ export class DefaultNotificationsService implements NotificationsServiceAbstract
) {
this.systemNotificationService.notificationClicked$
.pipe(
map(async (value: SystemNotificationEvent) => {
switch (value.type) {
case ButtonActions.AuthRequestNotification:
await this.actionService.openPopup();
}
}),
filter(
(event: SystemNotificationEvent) => event.type === ButtonActions.AuthRequestNotification,
),
mergeMap((event: SystemNotificationEvent) =>
this.handleAuthRequestNotificationClicked(event),
),
)
.subscribe();
@@ -92,6 +93,26 @@ export class DefaultNotificationsService implements NotificationsServiceAbstract
);
}
/**
* TODO: Requests are doubling, figure out if a subscription is duplicating or something.
* @param event
* @private
*/
private async handleAuthRequestNotificationClicked(
event: SystemNotificationEvent,
): Promise<void> {
// This is the approval event. WE WILL NOT BE USING 0 or 1!
if (event.buttonIdentifier === ButtonLocation.FirstOptionalButton) {
this.logService.info("Approve the request");
} else if (event.buttonIdentifier === ButtonLocation.SecondOptionalButton) {
// This is the deny event.
this.logService.info("Deny the request");
} else if (event.buttonIdentifier === ButtonLocation.NotificationButton) {
this.logService.info("Main button clicked, open popup");
await this.actionService.openPopup();
}
}
/**
* Retrieves a stream of push notifications for the given user.
* @param userId The user id of the user to get the push notifications for.

View File

@@ -42,7 +42,7 @@ export type SystemNotificationEvent = {
export abstract class SystemNotificationsService {
abstract notificationClicked$: Observable<SystemNotificationEvent>;
abstract create(createInfo: SystemNotificationCreateInfo): Promise<undefined>;
abstract clear(clearInfo: SystemNotificationClearInfo): undefined;
abstract clear(clearInfo: SystemNotificationClearInfo): Promise<void>;
/**
* Used to know if a given platform supports notifications.