mirror of
https://github.com/bitwarden/browser
synced 2026-02-27 18:13:29 +00:00
feat(notification-processing): [PM-19877] System Notification Implementation - Trying to have the notification present to prompt the browser extension to popup
This commit is contained in:
@@ -3,13 +3,4 @@ export abstract class ActionsService {
|
||||
* Opens the popup.
|
||||
*/
|
||||
abstract openPopup(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Opens the popup and navigates to a url.
|
||||
*
|
||||
* Stubbed for now.
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
abstract openPopupToUrl(url: string): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,4 @@ export class UnsupportedActionsService implements ActionsService {
|
||||
openPopup(): Promise<void> {
|
||||
throw new Error("Open Popup unsupported.");
|
||||
}
|
||||
|
||||
openPopupToUrl(url: string): Promise<void> {
|
||||
throw new Error("Open Popup to Url unsupported.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ import {
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { LogoutReason } from "@bitwarden/auth/common";
|
||||
import { ActionsService } from "@bitwarden/common/platform/actions";
|
||||
import {
|
||||
ButtonActions,
|
||||
SystemNotificationEvent,
|
||||
SystemNotificationsService,
|
||||
} from "@bitwarden/common/platform/notifications/system-notifications-service";
|
||||
|
||||
import { AccountService } from "../../../auth/abstractions/account.service";
|
||||
import { AuthService } from "../../../auth/abstractions/auth.service";
|
||||
@@ -56,8 +61,20 @@ export class DefaultNotificationsService implements NotificationsServiceAbstract
|
||||
private readonly signalRConnectionService: SignalRConnectionService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly webPushConnectionService: WebPushConnectionService,
|
||||
private readonly actionsService: ActionsService,
|
||||
private readonly systemNotificationService: SystemNotificationsService,
|
||||
private readonly actionService: ActionsService,
|
||||
) {
|
||||
this.systemNotificationService.notificationClicked$
|
||||
.pipe(
|
||||
map(async (value: SystemNotificationEvent) => {
|
||||
switch (value.type) {
|
||||
case ButtonActions.AuthRequestNotification:
|
||||
await this.actionService.openPopup();
|
||||
}
|
||||
}),
|
||||
)
|
||||
.subscribe();
|
||||
|
||||
this.notifications$ = this.accountService.activeAccount$.pipe(
|
||||
map((account) => account?.id),
|
||||
distinctUntilChanged(),
|
||||
@@ -215,7 +232,6 @@ export class DefaultNotificationsService implements NotificationsServiceAbstract
|
||||
await this.syncService.syncDeleteSend(notification.payload as SyncSendNotification);
|
||||
break;
|
||||
case NotificationType.AuthRequest:
|
||||
await this.actionsService.openPopup();
|
||||
this.messagingService.send("openLoginApproval", {
|
||||
notificationId: notification.payload.id,
|
||||
});
|
||||
|
||||
@@ -35,11 +35,11 @@ export type SystemNotificationClearInfo = {
|
||||
|
||||
export type SystemNotificationEvent = {
|
||||
id: string;
|
||||
type: string;
|
||||
type: ButtonActionsKeys;
|
||||
buttonIdentifier: number;
|
||||
};
|
||||
|
||||
export abstract class SystemNotificationService {
|
||||
export abstract class SystemNotificationsService {
|
||||
abstract notificationClicked$: Observable<SystemNotificationEvent>;
|
||||
abstract create(createInfo: SystemNotificationCreateInfo): Promise<undefined>;
|
||||
abstract clear(clearInfo: SystemNotificationClearInfo): undefined;
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
SystemNotificationClearInfo,
|
||||
SystemNotificationCreateInfo,
|
||||
SystemNotificationEvent,
|
||||
SystemNotificationService,
|
||||
} from "./system-notification-service";
|
||||
SystemNotificationsService,
|
||||
} from "./system-notifications-service";
|
||||
|
||||
export class UnsupportedSystemNotificationService implements SystemNotificationService {
|
||||
export class UnsupportedSystemNotificationsService implements SystemNotificationsService {
|
||||
private systemNotificationClickedSubject = new Subject<SystemNotificationEvent>();
|
||||
notificationClicked$ = throwError(() => new Error("Notification clicked is not supported."));
|
||||
|
||||
Reference in New Issue
Block a user