2018-04-04 04:14:54 +02:00
import { APP_INITIALIZER , LOCALE_ID , NgModule } from "@angular/core" ;
2021-12-21 15:43:35 +01:00
2022-06-14 17:10:53 +02:00
import { LockGuard as BaseLockGuardService } from "@bitwarden/angular/guards/lock.guard" ;
import { UnauthGuard as BaseUnauthGuardService } from "@bitwarden/angular/guards/unauth.guard" ;
2022-09-07 22:23:32 +02:00
import { MEMORY_STORAGE , SECURE_STORAGE } from "@bitwarden/angular/services/injection-tokens" ;
import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module" ;
2022-07-14 20:47:45 +02:00
import { ThemingService } from "@bitwarden/angular/services/theming/theming.service" ;
import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service" ;
import { AppIdService } from "@bitwarden/common/abstractions/appId.service" ;
import { AuditService } from "@bitwarden/common/abstractions/audit.service" ;
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/abstractions/auth.service" ;
import { CipherService } from "@bitwarden/common/abstractions/cipher.service" ;
import { CollectionService } from "@bitwarden/common/abstractions/collection.service" ;
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service" ;
import { CryptoFunctionService } from "@bitwarden/common/abstractions/cryptoFunction.service" ;
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service" ;
import { EventService } from "@bitwarden/common/abstractions/event.service" ;
import { ExportService } from "@bitwarden/common/abstractions/export.service" ;
2022-06-29 23:15:29 +02:00
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service" ;
2022-06-14 17:10:53 +02:00
import { FileUploadService } from "@bitwarden/common/abstractions/fileUpload.service" ;
2022-07-08 15:40:31 +02:00
import { FolderApiServiceAbstraction } from "@bitwarden/common/abstractions/folder/folder-api.service.abstraction" ;
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { I18nService } from "@bitwarden/common/abstractions/i18n.service" ;
import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service" ;
import { LogService as LogServiceAbstraction } from "@bitwarden/common/abstractions/log.service" ;
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service" ;
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service" ;
2022-09-27 22:25:19 +02:00
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service" ;
import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "@bitwarden/common/abstractions/passwordReprompt.service" ;
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service" ;
2022-08-08 11:04:36 +02:00
import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction" ;
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { ProviderService } from "@bitwarden/common/abstractions/provider.service" ;
import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abstractions/search.service" ;
import { SendService } from "@bitwarden/common/abstractions/send.service" ;
import { SettingsService } from "@bitwarden/common/abstractions/settings.service" ;
import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/abstractions/state.service" ;
2022-06-27 19:38:12 +02:00
import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service" ;
2022-08-29 20:14:59 +02:00
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { TokenService } from "@bitwarden/common/abstractions/token.service" ;
import { TotpService } from "@bitwarden/common/abstractions/totp.service" ;
import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service" ;
2022-08-10 03:31:02 +02:00
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction" ;
2022-06-14 17:10:53 +02:00
import { UsernameGenerationService } from "@bitwarden/common/abstractions/usernameGeneration.service" ;
2022-08-30 16:11:19 +02:00
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service" ;
2022-08-30 22:30:43 +02:00
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service" ;
2022-06-14 17:10:53 +02:00
import { AuthService } from "@bitwarden/common/services/auth.service" ;
import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service" ;
import { SearchService } from "@bitwarden/common/services/search.service" ;
2021-12-21 15:43:35 +01:00
2022-02-24 18:14:04 +01:00
import MainBackground from "../../background/main.background" ;
import { BrowserApi } from "../../browser/browserApi" ;
2018-04-04 14:27:31 +02:00
import { AutofillService } from "../../services/abstractions/autofill.service" ;
2022-02-24 18:14:04 +01:00
import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service" ;
2022-08-08 13:40:09 +02:00
import { BrowserEnvironmentService } from "../../services/browser-environment.service" ;
2022-06-29 23:15:29 +02:00
import { BrowserFileDownloadService } from "../../services/browserFileDownloadService" ;
2018-04-04 14:27:31 +02:00
import BrowserMessagingService from "../../services/browserMessaging.service" ;
2022-02-15 23:06:35 +01:00
import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service" ;
2022-05-09 14:19:18 +02:00
import { VaultFilterService } from "../../services/vaultFilter.service" ;
2021-12-21 15:43:35 +01:00
2022-02-24 18:14:04 +01:00
import { DebounceNavigationService } from "./debounceNavigationService" ;
2022-04-27 01:11:39 +02:00
import { InitService } from "./init.service" ;
2022-02-24 18:14:04 +01:00
import { LockGuardService } from "./lock-guard.service" ;
import { PasswordRepromptService } from "./password-reprompt.service" ;
2018-08-17 05:33:07 +02:00
import { PopupSearchService } from "./popup-search.service" ;
2018-04-05 21:35:56 +02:00
import { PopupUtilsService } from "./popup-utils.service" ;
2022-02-24 18:14:04 +01:00
import { UnauthGuardService } from "./unauth-guard.service" ;
2022-02-15 23:06:35 +01:00
const isPrivateMode = BrowserApi . getBackgroundPage ( ) == null ;
const mainBackground : MainBackground = isPrivateMode
? createLocalBgService ( )
: BrowserApi . getBackgroundPage ( ) . bitwardenMain ;
function createLocalBgService() {
const localBgService = new MainBackground ( true ) ;
localBgService . bootstrap ( ) ;
return localBgService ;
}
function getBgService < T > ( service : keyof MainBackground ) {
2018-04-04 14:27:31 +02:00
return ( ) : T = > {
2022-02-15 23:06:35 +01:00
return mainBackground ? ( mainBackground [ service ] as any as T ) : null ;
2018-04-04 14:27:31 +02:00
} ;
}
2018-04-04 04:14:54 +02:00
@NgModule ( {
2021-12-06 12:21:07 +01:00
imports : [ JslibServicesModule ] ,
2018-04-04 04:14:54 +02:00
declarations : [ ] ,
providers : [
2022-04-27 01:11:39 +02:00
InitService ,
DebounceNavigationService ,
2021-12-06 12:21:07 +01:00
{
provide : LOCALE_ID ,
2022-02-15 23:06:35 +01:00
useFactory : ( ) = > getBgService < I18nService > ( "i18nService" ) ( ) . translationLocale ,
2021-12-06 12:21:07 +01:00
deps : [ ] ,
} ,
{
provide : APP_INITIALIZER ,
2022-04-27 01:11:39 +02:00
useFactory : ( initService : InitService ) = > initService . init ( ) ,
deps : [ InitService ] ,
2021-12-06 12:21:07 +01:00
multi : true ,
2021-12-21 15:43:35 +01:00
} ,
2021-12-06 12:21:07 +01:00
{ provide : BaseLockGuardService , useClass : LockGuardService } ,
{ provide : BaseUnauthGuardService , useClass : UnauthGuardService } ,
2022-02-15 23:06:35 +01:00
{ provide : PopupUtilsService , useFactory : ( ) = > new PopupUtilsService ( isPrivateMode ) } ,
{
provide : MessagingService ,
useFactory : ( ) = > {
return isPrivateMode
? new BrowserMessagingPrivateModePopupService ( )
: new BrowserMessagingService ( ) ;
} ,
} ,
{
provide : TwoFactorService ,
useFactory : getBgService < TwoFactorService > ( "twoFactorService" ) ,
deps : [ ] ,
} ,
2021-03-17 22:14:26 +01:00
{
provide : AuthServiceAbstraction ,
useFactory : getBgService < AuthService > ( "authService" ) ,
deps : [ ] ,
} ,
2021-12-06 12:21:07 +01:00
{
provide : SearchServiceAbstraction ,
useFactory : (
cipherService : CipherService ,
logService : ConsoleLogService ,
i18nService : I18nService
) = > {
2022-02-15 23:06:35 +01:00
return new PopupSearchService (
getBgService < SearchService > ( "searchService" ) ( ) ,
cipherService ,
logService ,
i18nService
) ;
2021-12-06 12:21:07 +01:00
} ,
deps : [ CipherService , LogServiceAbstraction , I18nService ] ,
} ,
2018-04-04 14:27:31 +02:00
{ provide : AuditService , useFactory : getBgService < AuditService > ( "auditService" ) , deps : [ ] } ,
2021-03-29 17:16:31 +02:00
{
provide : FileUploadService ,
useFactory : getBgService < FileUploadService > ( "fileUploadService" ) ,
deps : [ ] ,
} ,
2018-04-04 14:27:31 +02:00
{ provide : CipherService , useFactory : getBgService < CipherService > ( "cipherService" ) , deps : [ ] } ,
2020-08-31 20:21:59 +02:00
{
provide : CryptoFunctionService ,
useFactory : getBgService < CryptoFunctionService > ( "cryptoFunctionService" ) ,
deps : [ ] ,
} ,
2022-07-08 15:40:31 +02:00
{
provide : FolderService ,
useFactory : getBgService < FolderService > ( "folderService" ) ,
deps : [ ] ,
} ,
{
provide : FolderApiServiceAbstraction ,
useFactory : getBgService < FolderApiServiceAbstraction > ( "folderApiService" ) ,
deps : [ ] ,
} ,
2018-04-04 14:27:31 +02:00
{
provide : CollectionService ,
useFactory : getBgService < CollectionService > ( "collectionService" ) ,
2021-07-23 22:32:42 +02:00
deps : [ ] ,
} ,
{
provide : LogServiceAbstraction ,
useFactory : getBgService < ConsoleLogService > ( "logService" ) ,
2018-04-04 14:27:31 +02:00
deps : [ ] ,
} ,
2022-08-08 13:40:09 +02:00
{
provide : BrowserEnvironmentService ,
useExisting : EnvironmentService ,
} ,
2018-04-04 14:27:31 +02:00
{
provide : EnvironmentService ,
useFactory : getBgService < EnvironmentService > ( "environmentService" ) ,
2021-12-21 15:43:35 +01:00
deps : [ ] ,
} ,
2018-04-04 14:27:31 +02:00
{ provide : TotpService , useFactory : getBgService < TotpService > ( "totpService" ) , deps : [ ] } ,
{ provide : TokenService , useFactory : getBgService < TokenService > ( "tokenService" ) , deps : [ ] } ,
2018-04-11 20:52:49 +02:00
{ provide : I18nService , useFactory : getBgService < I18nService > ( "i18nService" ) , deps : [ ] } ,
2018-04-04 14:27:31 +02:00
{ provide : CryptoService , useFactory : getBgService < CryptoService > ( "cryptoService" ) , deps : [ ] } ,
2019-07-14 17:58:17 +02:00
{ provide : EventService , useFactory : getBgService < EventService > ( "eventService" ) , deps : [ ] } ,
2022-08-08 11:04:36 +02:00
{
provide : PolicyService ,
useFactory : getBgService < PolicyService > ( "policyService" ) ,
deps : [ ] ,
} ,
{
provide : PolicyApiServiceAbstraction ,
useFactory : getBgService < PolicyApiServiceAbstraction > ( "policyApiService" ) ,
deps : [ ] ,
} ,
2018-04-04 14:27:31 +02:00
{
provide : PlatformUtilsService ,
useFactory : getBgService < PlatformUtilsService > ( "platformUtilsService" ) ,
2018-04-11 05:49:46 +02:00
deps : [ ] ,
2018-04-04 14:27:31 +02:00
} ,
{
provide : PasswordGenerationService ,
useFactory : getBgService < PasswordGenerationService > ( "passwordGenerationService" ) ,
2018-04-11 05:49:46 +02:00
deps : [ ] ,
2018-04-04 14:27:31 +02:00
} ,
{ provide : ApiService , useFactory : getBgService < ApiService > ( "apiService" ) , deps : [ ] } ,
{ provide : SyncService , useFactory : getBgService < SyncService > ( "syncService" ) , deps : [ ] } ,
{
provide : SettingsService ,
useFactory : getBgService < SettingsService > ( "settingsService" ) ,
deps : [ ] ,
} ,
{
2022-06-27 19:38:12 +02:00
provide : AbstractStorageService ,
useFactory : getBgService < AbstractStorageService > ( "storageService" ) ,
2021-12-21 15:43:35 +01:00
deps : [ ] ,
} ,
2018-04-04 14:27:31 +02:00
{ provide : AppIdService , useFactory : getBgService < AppIdService > ( "appIdService" ) , deps : [ ] } ,
{
provide : AutofillService ,
useFactory : getBgService < AutofillService > ( "autofillService" ) ,
deps : [ ] ,
} ,
2018-08-13 17:53:16 +02:00
{ provide : ExportService , useFactory : getBgService < ExportService > ( "exportService" ) , deps : [ ] } ,
2020-11-18 22:54:29 +01:00
{ provide : SendService , useFactory : getBgService < SendService > ( "sendService" ) , deps : [ ] } ,
2021-11-09 18:59:51 +01:00
{
provide : KeyConnectorService ,
useFactory : getBgService < KeyConnectorService > ( "keyConnectorService" ) ,
deps : [ ] ,
} ,
2021-11-16 11:50:58 +01:00
{
provide : UserVerificationService ,
useFactory : getBgService < UserVerificationService > ( "userVerificationService" ) ,
deps : [ ] ,
} ,
2022-08-30 22:30:43 +02:00
{
provide : VaultTimeoutSettingsService ,
useFactory : getBgService < VaultTimeoutSettingsService > ( "vaultTimeoutSettingsService" ) ,
deps : [ ] ,
} ,
2020-04-06 17:40:16 +02:00
{
provide : VaultTimeoutService ,
useFactory : getBgService < VaultTimeoutService > ( "vaultTimeoutService" ) ,
deps : [ ] ,
} ,
2018-08-20 23:40:39 +02:00
{
provide : NotificationsService ,
useFactory : getBgService < NotificationsService > ( "notificationsService" ) ,
deps : [ ] ,
} ,
2021-12-06 12:21:07 +01:00
{
provide : LogServiceAbstraction ,
useFactory : getBgService < ConsoleLogService > ( "logService" ) ,
deps : [ ] ,
} ,
2021-08-27 15:27:22 +02:00
{ provide : PasswordRepromptServiceAbstraction , useClass : PasswordRepromptService } ,
2022-01-27 22:22:51 +01:00
{
provide : OrganizationService ,
useFactory : getBgService < OrganizationService > ( "organizationService" ) ,
deps : [ ] ,
} ,
2022-05-09 14:19:18 +02:00
{
provide : VaultFilterService ,
useFactory : ( ) = > {
return new VaultFilterService (
getBgService < StateServiceAbstraction > ( "stateService" ) ( ) ,
getBgService < OrganizationService > ( "organizationService" ) ( ) ,
getBgService < FolderService > ( "folderService" ) ( ) ,
getBgService < CipherService > ( "cipherService" ) ( ) ,
getBgService < CollectionService > ( "collectionService" ) ( ) ,
getBgService < PolicyService > ( "policyService" ) ( )
) ;
} ,
deps : [ ] ,
} ,
2022-01-27 22:22:51 +01:00
{
provide : ProviderService ,
useFactory : getBgService < ProviderService > ( "providerService" ) ,
deps : [ ] ,
} ,
{
2022-04-27 01:11:39 +02:00
provide : SECURE_STORAGE ,
2022-06-27 19:38:12 +02:00
useFactory : getBgService < AbstractStorageService > ( "secureStorageService" ) ,
2022-01-27 22:22:51 +01:00
deps : [ ] ,
} ,
2022-06-27 19:38:12 +02:00
{
provide : MEMORY_STORAGE ,
useFactory : getBgService < AbstractStorageService > ( "memoryStorageService" ) ,
} ,
2022-01-27 22:22:51 +01:00
{
provide : StateServiceAbstraction ,
useFactory : getBgService < StateServiceAbstraction > ( "stateService" ) ,
deps : [ ] ,
} ,
2022-03-30 23:59:58 +02:00
{
provide : UsernameGenerationService ,
useFactory : getBgService < UsernameGenerationService > ( "usernameGenerationService" ) ,
deps : [ ] ,
} ,
2022-01-27 22:22:51 +01:00
{
provide : BaseStateServiceAbstraction ,
useExisting : StateServiceAbstraction ,
deps : [ ] ,
} ,
2022-06-29 23:15:29 +02:00
{
provide : FileDownloadService ,
useClass : BrowserFileDownloadService ,
} ,
2022-07-14 20:47:45 +02:00
{
provide : AbstractThemingService ,
useFactory : ( ) = > {
return new ThemingService (
getBgService < StateServiceAbstraction > ( "stateService" ) ( ) ,
// Safari doesn't properly handle the (prefers-color-scheme) media query in the popup window, it always returns light.
// In Safari we have to use the background page instead, which comes with limitations like not dynamically changing the extension theme when the system theme is changed.
getBgService < PlatformUtilsService > ( "platformUtilsService" ) ( ) . isSafari ( )
? getBgService < Window > ( "backgroundWindow" ) ( )
: window ,
document
) ;
} ,
} ,
2018-04-04 04:14:54 +02:00
] ,
} )
export class ServicesModule { }