1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-14 10:26:19 +01:00
bitwarden-browser/src/app/services/services.module.ts

130 lines
5.5 KiB
TypeScript
Raw Normal View History

import { webFrame } from 'electron';
2018-01-23 19:59:01 +01:00
2018-01-24 20:59:03 +01:00
import {
APP_INITIALIZER,
2018-01-24 21:22:13 +01:00
NgModule,
2018-01-24 20:59:03 +01:00
} from '@angular/core';
2018-01-23 05:37:36 +01:00
2018-01-23 19:59:01 +01:00
import { DesktopMessagingService } from '../../services/desktopMessaging.service';
import { DesktopPlatformUtilsService } from '../../services/desktopPlatformUtils.service';
import { DesktopStorageService } from '../../services/desktopStorage.service';
2018-01-23 21:08:57 +01:00
import { DesktopSecureStorageService } from '../../services/desktopSecureStorage.service';
2018-01-24 20:59:03 +01:00
import { I18nService } from '../../services/i18n.service';
2018-01-23 05:37:36 +01:00
2018-01-26 16:50:06 +01:00
import { Analytics } from 'jslib/misc/analytics';
2018-01-23 05:37:36 +01:00
import {
ApiService,
AppIdService,
AuthService,
CipherService,
CollectionService,
ConstantsService,
ContainerService,
CryptoService,
EnvironmentService,
FolderService,
LockService,
PasswordGenerationService,
SettingsService,
SyncService,
TokenService,
TotpService,
UserService,
UtilsService,
} from 'jslib/services';
import {
ApiService as ApiServiceAbstraction,
AppIdService as AppIdServiceAbstraction,
AuthService as AuthServiceAbstraction,
CipherService as CipherServiceAbstraction,
CollectionService as CollectionServiceAbstraction,
CryptoService as CryptoServiceAbstraction,
EnvironmentService as EnvironmentServiceAbstraction,
FolderService as FolderServiceAbstraction,
2018-01-25 20:25:44 +01:00
I18nService as I18nServiceAbstraction,
2018-01-23 05:37:36 +01:00
LockService as LockServiceAbstraction,
MessagingService as MessagingServiceAbstraction,
PasswordGenerationService as PasswordGenerationServiceAbstraction,
PlatformUtilsService as PlatformUtilsServiceAbstraction,
SettingsService as SettingsServiceAbstraction,
StorageService as StorageServiceAbstraction,
SyncService as SyncServiceAbstraction,
TokenService as TokenServiceAbstraction,
TotpService as TotpServiceAbstraction,
UserService as UserServiceAbstraction,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
webFrame.registerURLSchemeAsPrivileged('file');
2018-01-25 02:52:51 +01:00
const i18nService = new I18nService(window.navigator.language, './locales');
2018-01-23 05:37:36 +01:00
const utilsService = new UtilsService();
2018-01-25 20:25:44 +01:00
const platformUtilsService = new DesktopPlatformUtilsService(i18nService);
2018-01-23 05:37:36 +01:00
const messagingService = new DesktopMessagingService();
const storageService: StorageServiceAbstraction = new DesktopStorageService();
2018-01-23 21:08:57 +01:00
const secureStorageService: StorageServiceAbstraction = new DesktopSecureStorageService();
2018-01-23 05:37:36 +01:00
const constantsService = new ConstantsService({}, 0);
2018-01-23 21:08:57 +01:00
const cryptoService = new CryptoService(storageService, storageService); // TODO: use secure storage
2018-01-23 05:37:36 +01:00
const tokenService = new TokenService(storageService);
const appIdService = new AppIdService(storageService);
const apiService = new ApiService(tokenService, platformUtilsService,
(expired: boolean) => { /* log out */ });
const environmentService = new EnvironmentService(apiService, storageService);
const userService = new UserService(tokenService, storageService);
const settingsService = new SettingsService(userService, storageService);
const cipherService = new CipherService(cryptoService, userService, settingsService,
apiService, storageService);
const folderService = new FolderService(cryptoService, userService,
2018-01-26 20:12:41 +01:00
() => i18nService.t('noneFolder'), apiService, storageService);
2018-01-23 05:37:36 +01:00
const collectionService = new CollectionService(cryptoService, userService, storageService);
const lockService = new LockService(cipherService, folderService, collectionService,
cryptoService, platformUtilsService, storageService,
() => { /* set icon */ }, () => { /* refresh badge and menu */ });
const syncService = new SyncService(userService, apiService, settingsService,
folderService, cipherService, cryptoService, collectionService,
storageService, messagingService, (expired: boolean) => { /* log out */ });
const passwordGenerationService = new PasswordGenerationService(cryptoService, storageService);
const totpService = new TotpService(storageService);
const containerService = new ContainerService(cryptoService, platformUtilsService);
const authService: AuthServiceAbstraction = new AuthService(cryptoService, apiService,
userService, tokenService, appIdService, platformUtilsService, constantsService,
messagingService);
2018-01-26 16:50:06 +01:00
const analytics = new Analytics(window, null, platformUtilsService, storageService, appIdService);
containerService.attachToWindow(window);
environmentService.setUrlsFromStorage().then(() => {
return syncService.fullSync(true);
});
2018-01-24 20:59:03 +01:00
function initFactory(i18n: I18nService): Function {
return () => i18n.init();
}
2018-01-23 05:37:36 +01:00
@NgModule({
imports: [],
declarations: [],
providers: [
{ provide: AuthServiceAbstraction, useValue: authService },
{ provide: CipherServiceAbstraction, useValue: cipherService },
{ provide: FolderServiceAbstraction, useValue: folderService },
{ provide: CollectionServiceAbstraction, useValue: collectionService },
2018-01-23 23:29:30 +01:00
{ provide: EnvironmentServiceAbstraction, useValue: environmentService },
2018-01-25 05:26:40 +01:00
{ provide: TotpServiceAbstraction, useValue: totpService },
{ provide: TokenServiceAbstraction, useValue: tokenService },
2018-01-25 20:25:44 +01:00
{ provide: I18nServiceAbstraction, useValue: i18nService },
{ provide: UtilsServiceAbstraction, useValue: utilsService },
{ provide: CryptoServiceAbstraction, useValue: cryptoService },
{ provide: PlatformUtilsServiceAbstraction, useValue: platformUtilsService },
2018-01-24 20:59:03 +01:00
{
provide: APP_INITIALIZER,
useFactory: initFactory,
2018-01-25 20:25:44 +01:00
deps: [I18nServiceAbstraction],
2018-01-24 21:22:13 +01:00
multi: true,
},
2018-01-23 05:37:36 +01:00
],
})
export class ServicesModule {
}