1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-21 11:54:02 +00:00

initial work

This commit is contained in:
Patrick Pimentel
2025-05-29 10:38:03 -04:00
parent b48356228c
commit 04748b65d8
3 changed files with 158 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
import { Observable } from "rxjs";
export const ButtonActions = {
AuthRequestNotification: "authRequestNotification",
};
export type ButtonActionsKeys = (typeof ButtonActions)[keyof typeof ButtonActions];
// This is currently tailored for chrome extension's api, if safari works
// differently where clicking a notification button produces a different
// identifier we need to reconcile that here.
export const ButtonLocation = {
FirstOptionalButton: 0, // this is the first optional button we can set
SecondOptionalButton: 1, // this is the second optional button we can set
NotificationButton: 2, // this is when you click the notification as a whole
};
export type ButtonLocationKeys = (typeof ButtonLocation)[keyof typeof ButtonLocation];
export type SystemNotificationsButton = {
title: string;
};
export type SystemNotificationCreateInfo = {
id: string;
type: ButtonActionsKeys;
title: string;
body: string;
buttons: SystemNotificationsButton[];
};
export type SystemNotificationClearInfo = {
id: string;
};
export type SystemNotificationEvent = {
id: string;
type: string;
buttonIdentifier: number;
};
export abstract class SystemNotificationService {
abstract notificationClicked$: Observable<SystemNotificationEvent>;
abstract create(createInfo: SystemNotificationCreateInfo): Promise<undefined>;
abstract clear(clearInfo: SystemNotificationClearInfo): undefined;
/**
* Used to know if a given platform supports notifications.
*/
abstract isSupported(): boolean;
}

View File

@@ -0,0 +1,25 @@
import { Subject, throwError } from "rxjs";
import {
SystemNotificationClearInfo,
SystemNotificationCreateInfo,
SystemNotificationEvent,
SystemNotificationService,
} from "./system-notification-service";
export class UnsupportedSystemNotificationService implements SystemNotificationService {
private systemNotificationClickedSubject = new Subject<SystemNotificationEvent>();
notificationClicked$ = throwError(() => new Error("Notification clicked is not supported."));
async create(createInfo: SystemNotificationCreateInfo): Promise<undefined> {
throw new Error("Create OS Notification unsupported.");
}
clear(clearInfo: SystemNotificationClearInfo): undefined {
throw new Error("Clear OS Notification unsupported.");
}
isSupported(): boolean {
return false;
}
}