1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 13:10:17 +00:00

feat(extension-notification-demo): Updated more of how the inheritance structure would work.

This commit is contained in:
Patrick Pimentel
2025-04-17 13:09:02 -04:00
parent 90098d0822
commit 70230b77d0
3 changed files with 23 additions and 8 deletions

View File

@@ -135,7 +135,6 @@ import {
WorkerWebPushConnectionService,
} from "@bitwarden/common/platform/notifications/internal";
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
import { ChromeExtensionSystemNotificationService } from "@bitwarden/common/platform/services/chrome-extension-system-notification.service";
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
@@ -151,6 +150,7 @@ import { DefaultSdkClientFactory } from "@bitwarden/common/platform/services/sdk
import { DefaultSdkService } from "@bitwarden/common/platform/services/sdk/default-sdk.service";
import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
import { StateService } from "@bitwarden/common/platform/services/state.service";
import { SystemNotificationService } from "@bitwarden/common/platform/services/system-notification.service";
import { SystemService } from "@bitwarden/common/platform/services/system.service";
import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service";
import {
@@ -1086,7 +1086,7 @@ export default class MainBackground {
this.webPushConnectionService = new UnsupportedWebPushConnectionService();
}
this.systemNotificationService = new ChromeExtensionSystemNotificationService(
this.systemNotificationService = new SystemNotificationService(
this.logService,
this.platformUtilsService,
);

View File

@@ -210,7 +210,6 @@ import {
TaskSchedulerService,
} from "@bitwarden/common/platform/scheduling";
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
import { ChromeExtensionSystemNotificationService } from "@bitwarden/common/platform/services/chrome-extension-system-notification.service";
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
@@ -224,6 +223,7 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r
import { DefaultSdkService } from "@bitwarden/common/platform/services/sdk/default-sdk.service";
import { StateService } from "@bitwarden/common/platform/services/state.service";
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
import { SystemNotificationService } from "@bitwarden/common/platform/services/system-notification.service";
import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service";
import { ValidationService } from "@bitwarden/common/platform/services/validation.service";
import {
@@ -900,7 +900,7 @@ const safeProviders: SafeProvider[] = [
}),
safeProvider({
provide: SystemNotificationServiceAbstraction,
useClass: ChromeExtensionSystemNotificationService,
useClass: SystemNotificationService,
deps: [LogService, PlatformUtilsServiceAbstraction],
}),
safeProvider({

View File

@@ -1,5 +1,6 @@
import { Observable, Subject } from "rxjs";
import { DeviceType } from "@bitwarden/common/enums";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import {
@@ -10,9 +11,7 @@ import {
SystemNotificationServiceAbstraction as SystemNotificationServiceAbstraction,
} from "@bitwarden/common/platform/abstractions/system-notification-service.abstraction";
export class ChromeExtensionSystemNotificationService
implements SystemNotificationServiceAbstraction
{
export class SystemNotificationService implements SystemNotificationServiceAbstraction {
private systemNotificationClickedSubject = new Subject<SystemNotificationEvent>();
systemNotificationClicked$: Observable<SystemNotificationEvent>;
@@ -24,6 +23,10 @@ export class ChromeExtensionSystemNotificationService
}
async createOSNotification(createInfo: SystemNotificationCreateInfo): Promise<undefined> {
if (!this.isSupported()) {
this.logService.error("While trying to createOSNotification, found that it is not supported");
}
chrome.notifications.create(createInfo.id, {
iconUrl: "https://avatars.githubusercontent.com/u/15990069?s=200",
message: createInfo.title,
@@ -58,10 +61,22 @@ export class ChromeExtensionSystemNotificationService
}
clearOSNotification(clearInfo: SystemNotificationClearInfo): undefined {
if (!this.isSupported()) {
this.logService.error("While trying to clearOSNotification, found that it is not supported");
}
chrome.notifications.clear(clearInfo.id);
}
isSupported(): boolean {
return true;
switch (this.platformUtilsService.getDevice()) {
case DeviceType.EdgeExtension:
case DeviceType.VivaldiExtension:
case DeviceType.OperaExtension:
case DeviceType.ChromeExtension:
return true;
default:
return false;
}
}
}