From cae2484cc7b84db7be16189c6e41e5ec206b4cb1 Mon Sep 17 00:00:00 2001 From: Patrick Pimentel Date: Thu, 17 Apr 2025 13:40:03 -0400 Subject: [PATCH] feat(extension-notification-demo): Restructured some of the files. --- .../browser/src/background/main.background.ts | 6 ++-- .../src/popup/services/services.module.ts | 7 +++++ .../src/services/jslib-services.module.ts | 8 ++--- ...extension-auth-request-approval.service.ts | 2 +- .../browser-system-notification.service.ts} | 4 +-- .../platform/system-notifications/index.ts | 2 ++ ...system-notification-service.abstraction.ts | 0 ...unsupported-system-notification.service.ts | 29 +++++++++++++++++++ 8 files changed, 48 insertions(+), 10 deletions(-) rename libs/common/src/platform/{services/system-notification.service.ts => system-notifications/browser-system-notification.service.ts} (93%) create mode 100644 libs/common/src/platform/system-notifications/index.ts rename libs/common/src/platform/{abstractions => system-notifications}/system-notification-service.abstraction.ts (100%) create mode 100644 libs/common/src/platform/system-notifications/unsupported-system-notification.service.ts diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 1262b33dd91..ea0a3c323e0 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -114,7 +114,6 @@ import { AbstractStorageService, ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; -import { SystemNotificationServiceAbstraction } from "@bitwarden/common/platform/abstractions/system-notification-service.abstraction"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { IpcService } from "@bitwarden/common/platform/ipc"; @@ -150,7 +149,6 @@ 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 { @@ -174,6 +172,8 @@ import { WindowStorageService } from "@bitwarden/common/platform/storage/window- import { SyncService } from "@bitwarden/common/platform/sync"; // eslint-disable-next-line no-restricted-imports -- Needed for service creation import { DefaultSyncService } from "@bitwarden/common/platform/sync/internal"; +import { BrowserSystemNotificationService } from "@bitwarden/common/platform/system-notifications/browser-system-notification.service"; +import { SystemNotificationServiceAbstraction } from "@bitwarden/common/platform/system-notifications/system-notification-service.abstraction"; import { DefaultThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; import { ApiService } from "@bitwarden/common/services/api.service"; import { AuditService } from "@bitwarden/common/services/audit.service"; @@ -1086,7 +1086,7 @@ export default class MainBackground { this.webPushConnectionService = new UnsupportedWebPushConnectionService(); } - this.systemNotificationService = new SystemNotificationService( + this.systemNotificationService = new BrowserSystemNotificationService( this.logService, this.platformUtilsService, ); diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index dad4e887a12..42b033889f1 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -112,6 +112,8 @@ import { InlineDerivedStateProvider } from "@bitwarden/common/platform/state/imp import { PrimarySecondaryStorageService } from "@bitwarden/common/platform/storage/primary-secondary-storage.service"; import { WindowStorageService } from "@bitwarden/common/platform/storage/window-storage.service"; import { SyncService } from "@bitwarden/common/platform/sync"; +import { SystemNotificationServiceAbstraction } from "@bitwarden/common/platform/system-notifications"; +import { BrowserSystemNotificationService } from "@bitwarden/common/platform/system-notifications/browser-system-notification.service"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { InternalSendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; @@ -667,6 +669,11 @@ const safeProviders: SafeProvider[] = [ useClass: ForegroundNotificationsService, deps: [LogService], }), + safeProvider({ + provide: SystemNotificationServiceAbstraction, + useClass: BrowserSystemNotificationService, + deps: [LogService, PlatformUtilsService], // Add any other dependencies your service needs + }), ]; @NgModule({ diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index e3af2ed43ce..3355d070e78 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -186,7 +186,6 @@ import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sd import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { SystemNotificationServiceAbstraction } from "@bitwarden/common/platform/abstractions/system-notification-service.abstraction"; import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; @@ -223,7 +222,6 @@ 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 { @@ -245,6 +243,8 @@ import { StateEventRunnerService } from "@bitwarden/common/platform/state/state- import { SyncService } from "@bitwarden/common/platform/sync"; // eslint-disable-next-line no-restricted-imports -- Needed for DI import { DefaultSyncService } from "@bitwarden/common/platform/sync/internal"; +import { UnsupportedSystemNotificationService } from "@bitwarden/common/platform/system-notifications"; +import { SystemNotificationServiceAbstraction } from "@bitwarden/common/platform/system-notifications/system-notification-service.abstraction"; import { DefaultThemeStateService, ThemeStateService, @@ -900,8 +900,8 @@ const safeProviders: SafeProvider[] = [ }), safeProvider({ provide: SystemNotificationServiceAbstraction, - useClass: SystemNotificationService, - deps: [LogService, PlatformUtilsServiceAbstraction], + useClass: UnsupportedSystemNotificationService, + deps: [], }), safeProvider({ provide: AuthRequestLoginApprovalAbstraction, diff --git a/libs/common/src/auth/services/devices/chrome-browser-extension-auth-request-approval.service.ts b/libs/common/src/auth/services/devices/chrome-browser-extension-auth-request-approval.service.ts index b9b8245112b..9579716e39f 100644 --- a/libs/common/src/auth/services/devices/chrome-browser-extension-auth-request-approval.service.ts +++ b/libs/common/src/auth/services/devices/chrome-browser-extension-auth-request-approval.service.ts @@ -7,7 +7,7 @@ import { SystemNotificationServiceAbstraction, SystemNotificationEvent, ButtonLocation, -} from "@bitwarden/common/platform/abstractions/system-notification-service.abstraction"; +} from "@bitwarden/common/platform/system-notifications/system-notification-service.abstraction"; export abstract class AuthRequestLoginApprovalAbstraction { abstract receivedPendingAuthRequest(notificationId: string): Promise; diff --git a/libs/common/src/platform/services/system-notification.service.ts b/libs/common/src/platform/system-notifications/browser-system-notification.service.ts similarity index 93% rename from libs/common/src/platform/services/system-notification.service.ts rename to libs/common/src/platform/system-notifications/browser-system-notification.service.ts index c95227da4a5..576a5dfe664 100644 --- a/libs/common/src/platform/services/system-notification.service.ts +++ b/libs/common/src/platform/system-notifications/browser-system-notification.service.ts @@ -9,9 +9,9 @@ import { SystemNotificationCreateInfo, SystemNotificationEvent, SystemNotificationServiceAbstraction as SystemNotificationServiceAbstraction, -} from "@bitwarden/common/platform/abstractions/system-notification-service.abstraction"; +} from "@bitwarden/common/platform/system-notifications/system-notification-service.abstraction"; -export class SystemNotificationService implements SystemNotificationServiceAbstraction { +export class BrowserSystemNotificationService implements SystemNotificationServiceAbstraction { private systemNotificationClickedSubject = new Subject(); systemNotificationClicked$: Observable; diff --git a/libs/common/src/platform/system-notifications/index.ts b/libs/common/src/platform/system-notifications/index.ts new file mode 100644 index 00000000000..fff5f1e276c --- /dev/null +++ b/libs/common/src/platform/system-notifications/index.ts @@ -0,0 +1,2 @@ +export * from "./system-notification-service.abstraction"; +export * from "./unsupported-system-notification.service"; diff --git a/libs/common/src/platform/abstractions/system-notification-service.abstraction.ts b/libs/common/src/platform/system-notifications/system-notification-service.abstraction.ts similarity index 100% rename from libs/common/src/platform/abstractions/system-notification-service.abstraction.ts rename to libs/common/src/platform/system-notifications/system-notification-service.abstraction.ts diff --git a/libs/common/src/platform/system-notifications/unsupported-system-notification.service.ts b/libs/common/src/platform/system-notifications/unsupported-system-notification.service.ts new file mode 100644 index 00000000000..debb1b8fbc3 --- /dev/null +++ b/libs/common/src/platform/system-notifications/unsupported-system-notification.service.ts @@ -0,0 +1,29 @@ +import { Observable, Subject } from "rxjs"; + +import { + SystemNotificationClearInfo, + SystemNotificationCreateInfo, + SystemNotificationEvent, + SystemNotificationServiceAbstraction as SystemNotificationServiceAbstraction, +} from "@bitwarden/common/platform/system-notifications/system-notification-service.abstraction"; + +export class UnsupportedSystemNotificationService implements SystemNotificationServiceAbstraction { + private systemNotificationClickedSubject = new Subject(); + systemNotificationClicked$: Observable; + + constructor() { + this.systemNotificationClicked$ = this.systemNotificationClickedSubject.asObservable(); + } + + async createOSNotification(createInfo: SystemNotificationCreateInfo): Promise { + throw new Error("Create OS Notification unsupported."); + } + + clearOSNotification(clearInfo: SystemNotificationClearInfo): undefined { + throw new Error("Clear OS Notification unsupported."); + } + + isSupported(): boolean { + return false; + } +}