1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-01 08:20:41 +01:00
bitwarden-desktop/src/app/services.module.ts

232 lines
14 KiB
TypeScript
Raw Normal View History

2018-05-31 15:08:09 +02:00
import { remote } from 'electron';
2018-01-24 20:59:03 +01:00
import {
APP_INITIALIZER,
2018-08-02 15:26:50 +02:00
LOCALE_ID,
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-31 05:34:45 +01:00
import { ToasterModule } from 'angular2-toaster';
2018-04-24 22:30:47 +02:00
import { ElectronLogService } from 'jslib/electron/services/electronLog.service';
import { ElectronPlatformUtilsService } from 'jslib/electron/services/electronPlatformUtils.service';
import { ElectronRendererMessagingService } from 'jslib/electron/services/electronRendererMessaging.service';
2018-04-24 22:30:47 +02:00
import { ElectronRendererSecureStorageService } from 'jslib/electron/services/electronRendererSecureStorage.service';
2019-03-12 03:37:13 +01:00
import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service';
2018-04-24 22:30:47 +02:00
import { isDev } from 'jslib/electron/utils';
2018-02-16 21:06:54 +01:00
2019-07-24 20:48:08 +02:00
import { DeviceType } from 'jslib/enums/deviceType';
2018-04-25 05:26:50 +02:00
import { I18nService } from '../services/i18n.service';
import { NativeMessagingService } from '../services/nativeMessaging.service';
2018-01-23 05:37:36 +01:00
2018-04-04 14:30:14 +02:00
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
2018-04-06 21:33:53 +02:00
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
2018-04-04 14:30:14 +02:00
import { ValidationService } from 'jslib/angular/services/validation.service';
2018-01-31 05:34:45 +01:00
2018-01-26 16:50:06 +01:00
import { Analytics } from 'jslib/misc/analytics';
import { ApiService } from 'jslib/services/api.service';
import { AppIdService } from 'jslib/services/appId.service';
import { AuditService } from 'jslib/services/audit.service';
import { AuthService } from 'jslib/services/auth.service';
import { CipherService } from 'jslib/services/cipher.service';
import { CollectionService } from 'jslib/services/collection.service';
import { ConstantsService } from 'jslib/services/constants.service';
import { ContainerService } from 'jslib/services/container.service';
import { CryptoService } from 'jslib/services/crypto.service';
import { EnvironmentService } from 'jslib/services/environment.service';
2019-07-09 19:11:10 +02:00
import { EventService } from 'jslib/services/event.service';
2018-05-17 16:54:24 +02:00
import { ExportService } from 'jslib/services/export.service';
import { FolderService } from 'jslib/services/folder.service';
2018-08-20 22:23:55 +02:00
import { NotificationsService } from 'jslib/services/notifications.service';
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
2020-01-31 04:11:16 +01:00
import { PolicyService } from 'jslib/services/policy.service';
2018-08-13 15:43:46 +02:00
import { SearchService } from 'jslib/services/search.service';
import { SettingsService } from 'jslib/services/settings.service';
import { StateService } from 'jslib/services/state.service';
import { SyncService } from 'jslib/services/sync.service';
2019-02-27 17:29:31 +01:00
import { SystemService } from 'jslib/services/system.service';
import { TokenService } from 'jslib/services/token.service';
import { TotpService } from 'jslib/services/totp.service';
import { UserService } from 'jslib/services/user.service';
import { VaultTimeoutService } from 'jslib/services/vaultTimeout.service';
2018-05-30 22:52:55 +02:00
import { WebCryptoFunctionService } from 'jslib/services/webCryptoFunction.service';
2018-01-23 05:37:36 +01:00
import { ApiService as ApiServiceAbstraction } from 'jslib/abstractions/api.service';
import { AppIdService as AppIdServiceAbstraction } from 'jslib/abstractions/appId.service';
import { AuditService as AuditServiceAbstraction } from 'jslib/abstractions/audit.service';
import { AuthService as AuthServiceAbstraction } from 'jslib/abstractions/auth.service';
import { CipherService as CipherServiceAbstraction } from 'jslib/abstractions/cipher.service';
import { CollectionService as CollectionServiceAbstraction } from 'jslib/abstractions/collection.service';
import { CryptoService as CryptoServiceAbstraction } from 'jslib/abstractions/crypto.service';
2018-04-22 05:14:58 +02:00
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from 'jslib/abstractions/cryptoFunction.service';
import { EnvironmentService as EnvironmentServiceAbstraction } from 'jslib/abstractions/environment.service';
2019-07-09 19:11:10 +02:00
import { EventService as EventServiceAbstraction } from 'jslib/abstractions/event.service';
2018-05-17 16:54:24 +02:00
import { ExportService as ExportServiceAbstraction } from 'jslib/abstractions/export.service';
import { FolderService as FolderServiceAbstraction } from 'jslib/abstractions/folder.service';
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
2018-02-24 05:12:06 +01:00
import { LogService as LogServiceAbstraction } from 'jslib/abstractions/log.service';
import { MessagingService as MessagingServiceAbstraction } from 'jslib/abstractions/messaging.service';
2018-08-20 22:23:55 +02:00
import { NotificationsService as NotificationsServiceAbstraction } from 'jslib/abstractions/notifications.service';
2018-01-23 05:37:36 +01:00
import {
PasswordGenerationService as PasswordGenerationServiceAbstraction,
} from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from 'jslib/abstractions/platformUtils.service';
2020-01-31 04:11:16 +01:00
import { PolicyService as PolicyServiceAbstraction } from 'jslib/abstractions/policy.service';
2018-08-13 15:43:46 +02:00
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
import { SettingsService as SettingsServiceAbstraction } from 'jslib/abstractions/settings.service';
import { StateService as StateServiceAbstraction } from 'jslib/abstractions/state.service';
import { StorageService as StorageServiceAbstraction } from 'jslib/abstractions/storage.service';
import { SyncService as SyncServiceAbstraction } from 'jslib/abstractions/sync.service';
2019-02-27 17:29:31 +01:00
import { SystemService as SystemServiceAbstraction } from 'jslib/abstractions/system.service';
import { TokenService as TokenServiceAbstraction } from 'jslib/abstractions/token.service';
import { TotpService as TotpServiceAbstraction } from 'jslib/abstractions/totp.service';
import { UserService as UserServiceAbstraction } from 'jslib/abstractions/user.service';
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from 'jslib/abstractions/vaultTimeout.service';
2018-01-23 05:37:36 +01:00
2018-04-24 22:30:47 +02:00
const logService = new ElectronLogService();
2018-01-25 02:52:51 +01:00
const i18nService = new I18nService(window.navigator.language, './locales');
2018-02-12 21:06:39 +01:00
const stateService = new StateService();
2018-02-08 18:24:17 +01:00
const broadcasterService = new BroadcasterService();
const messagingService = new ElectronRendererMessagingService(broadcasterService);
2019-03-12 03:37:13 +01:00
const storageService: StorageServiceAbstraction = new ElectronStorageService(remote.app.getPath('userData'));
const platformUtilsService = new ElectronPlatformUtilsService(i18nService, messagingService, true, storageService);
2018-04-24 22:30:47 +02:00
const secureStorageService: StorageServiceAbstraction = new ElectronRendererSecureStorageService();
2018-05-30 22:52:55 +02:00
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
platformUtilsService);
2018-04-22 05:14:58 +02:00
const cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
2018-01-23 05:37:36 +01:00
const tokenService = new TokenService(storageService);
const appIdService = new AppIdService(storageService);
const apiService = new ApiService(tokenService, platformUtilsService,
2018-05-16 05:40:24 +02:00
async (expired: boolean) => messagingService.send('logout', { expired: expired }));
2018-01-23 05:37:36 +01:00
const userService = new UserService(tokenService, storageService);
const settingsService = new SettingsService(userService, storageService);
2018-08-13 15:43:46 +02:00
export let searchService: SearchService = null;
2018-01-23 05:37:36 +01:00
const cipherService = new CipherService(cryptoService, userService, settingsService,
2018-10-14 04:47:27 +02:00
apiService, storageService, i18nService, () => searchService);
2018-06-25 20:55:30 +02:00
const folderService = new FolderService(cryptoService, userService, apiService, storageService,
i18nService, cipherService);
2018-01-27 04:39:45 +01:00
const collectionService = new CollectionService(cryptoService, userService, storageService, i18nService);
2020-09-15 17:00:05 +02:00
searchService = new SearchService(cipherService);
2020-01-31 04:11:16 +01:00
const policyService = new PolicyService(userService, storageService);
const vaultTimeoutService = new VaultTimeoutService(cipherService, folderService, collectionService,
cryptoService, platformUtilsService, storageService, messagingService, searchService, userService, tokenService,
null, async () => messagingService.send('logout', { expired: false }));
2018-01-23 05:37:36 +01:00
const syncService = new SyncService(userService, apiService, settingsService,
2020-01-31 04:11:16 +01:00
folderService, cipherService, cryptoService, collectionService, storageService, messagingService, policyService,
2018-05-16 05:40:24 +02:00
async (expired: boolean) => messagingService.send('logout', { expired: expired }));
const passwordGenerationService = new PasswordGenerationService(cryptoService, storageService, policyService);
2018-04-22 05:56:18 +02:00
const totpService = new TotpService(storageService, cryptoFunctionService);
2018-10-14 04:47:27 +02:00
const containerService = new ContainerService(cryptoService);
const authService = new AuthService(cryptoService, apiService, userService, tokenService, appIdService,
i18nService, platformUtilsService, messagingService, vaultTimeoutService);
2018-07-05 20:41:50 +02:00
const exportService = new ExportService(folderService, cipherService, apiService);
2018-07-08 05:51:05 +02:00
const auditService = new AuditService(cryptoFunctionService, apiService);
2018-08-24 21:30:26 +02:00
const notificationsService = new NotificationsService(userService, syncService, appIdService,
apiService, vaultTimeoutService, async () => messagingService.send('logout', { expired: true }));
2018-08-20 23:01:25 +02:00
const environmentService = new EnvironmentService(apiService, storageService, notificationsService);
2019-07-09 19:11:10 +02:00
const eventService = new EventService(storageService, apiService, userService, cipherService);
const systemService = new SystemService(storageService, vaultTimeoutService, messagingService, platformUtilsService,
null);
2020-10-16 17:09:17 +02:00
const nativeMessagingService = new NativeMessagingService(cryptoFunctionService, cryptoService, platformUtilsService, logService);
2018-01-23 05:37:36 +01:00
2018-05-31 04:42:13 +02:00
const analytics = new Analytics(window, () => isDev(), platformUtilsService, storageService, appIdService);
2018-10-14 04:47:27 +02:00
containerService.attachToGlobal(window);
export function initFactory(): Function {
2018-01-31 02:03:41 +01:00
return async () => {
2018-08-20 22:23:55 +02:00
await environmentService.setUrlsFromStorage();
syncService.fullSync(true);
vaultTimeoutService.init(true);
2018-04-25 05:53:20 +02:00
const locale = await storageService.get<string>(ConstantsService.localeKey);
await i18nService.init(locale);
2019-07-09 19:11:10 +02:00
eventService.init(true);
2018-10-04 18:05:32 +02:00
authService.init();
2018-08-20 22:23:55 +02:00
setTimeout(() => notificationsService.init(environmentService), 3000);
2018-01-31 02:03:41 +01:00
const htmlEl = window.document.documentElement;
2018-02-16 21:46:37 +01:00
htmlEl.classList.add('os_' + platformUtilsService.getDeviceString());
htmlEl.classList.add('locale_' + i18nService.translationLocale);
2018-05-30 21:39:20 +02:00
let theme = await storageService.get<string>(ConstantsService.themeKey);
if (theme == null) {
2019-07-24 20:48:08 +02:00
theme = platformUtilsService.getDevice() === DeviceType.MacOsDesktop &&
remote.systemPreferences.isDarkMode() ? 'dark' : 'light';
2018-05-30 05:28:58 +02:00
}
2018-05-30 21:39:20 +02:00
htmlEl.classList.add('theme_' + theme);
2018-02-12 21:06:39 +01:00
stateService.save(ConstantsService.disableFaviconKey,
await storageService.get<boolean>(ConstantsService.disableFaviconKey));
2018-02-16 21:46:37 +01:00
let installAction = null;
const installedVersion = await storageService.get<string>(ConstantsService.installedVersionKey);
const currentVersion = platformUtilsService.getApplicationVersion();
if (installedVersion == null) {
installAction = 'install';
} else if (installedVersion !== currentVersion) {
installAction = 'update';
}
if (installAction != null) {
await storageService.save(ConstantsService.installedVersionKey, currentVersion);
analytics.ga('send', {
hitType: 'event',
eventAction: installAction,
});
}
2018-01-31 02:03:41 +01:00
};
2018-01-24 20:59:03 +01:00
}
2018-01-23 05:37:36 +01:00
@NgModule({
2018-01-31 05:34:45 +01:00
imports: [
ToasterModule,
],
2018-01-23 05:37:36 +01:00
declarations: [],
providers: [
2018-01-31 05:34:45 +01:00
ValidationService,
2018-02-08 17:12:25 +01:00
AuthGuardService,
{ provide: AuditServiceAbstraction, useValue: auditService },
2018-01-23 05:37:36 +01:00
{ 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: CryptoServiceAbstraction, useValue: cryptoService },
{ provide: CryptoFunctionServiceAbstraction, useValue: cryptoFunctionService },
2018-01-25 20:25:44 +01:00
{ provide: PlatformUtilsServiceAbstraction, useValue: platformUtilsService },
2018-01-29 22:13:37 +01:00
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
2018-01-31 20:19:21 +01:00
{ provide: ApiServiceAbstraction, useValue: apiService },
2018-02-08 16:48:50 +01:00
{ provide: SyncServiceAbstraction, useValue: syncService },
2018-02-08 17:12:25 +01:00
{ provide: UserServiceAbstraction, useValue: userService },
2018-02-08 18:24:17 +01:00
{ provide: MessagingServiceAbstraction, useValue: messagingService },
{ provide: BroadcasterService, useValue: broadcasterService },
{ provide: SettingsServiceAbstraction, useValue: settingsService },
{ provide: VaultTimeoutServiceAbstraction, useValue: vaultTimeoutService },
2018-02-10 05:25:18 +01:00
{ provide: StorageServiceAbstraction, useValue: storageService },
2018-02-12 21:06:39 +01:00
{ provide: StateServiceAbstraction, useValue: stateService },
2018-02-24 05:12:06 +01:00
{ provide: LogServiceAbstraction, useValue: logService },
2018-05-17 16:54:24 +02:00
{ provide: ExportServiceAbstraction, useValue: exportService },
2018-08-13 15:43:46 +02:00
{ provide: SearchServiceAbstraction, useValue: searchService },
2018-08-20 22:23:55 +02:00
{ provide: NotificationsServiceAbstraction, useValue: notificationsService },
2019-02-27 17:29:31 +01:00
{ provide: SystemServiceAbstraction, useValue: systemService },
2019-07-09 19:11:10 +02:00
{ provide: EventServiceAbstraction, useValue: eventService },
2020-01-31 04:11:16 +01:00
{ provide: PolicyServiceAbstraction, useValue: policyService },
merge sso feature branch (#523) * Update jslib (101c568 -> 14b01f2) (#506) * Update jslib (14b01f2 -> 1513b25) (#510) * [jslib] Update (1513b25 -> 7c3a9d6) (#516) * update jslib (1513b25 -> 7c3a9d6) * Updated call to constructor super * [SSO] Added SSO flows & functionality (#513) * update jslib * bump version * Added sso button (wip) * Added sso & change password // Added modules/routes // Added strings for localization * Added password strength comp // reverted login route * Updated sso component to send client id // added routing for sso // added crypto function to services module provider list * Added deep linking * First round of UI updates // Added sso browser launching // Added missing strings * Updated UI and added missing strings * Removed extra change password style * Let constructor for WindowMain handle default width/height * Prepared for jslib update * Update jslib (1513b25 -> 7c3a9d6) * Update login super * Added params for launchSsoBrowser function * Update jslib (7c3a9d6 -> 4203937) * Added missing strings, removed unnecessary class param * Upgrade TypeScript (#517) * Updated password score // Update styles * Removed password-strength component files * Cleaned up module class // Fixed UL/LI formatting issues * Use exisiting loading string // removed new string * Update jslib (4203937 -> 9957125) * Updated class to perform new submit actions * Upgrade Angular (#520) * di resolution for CryptoFunctionServiceAbstraction * Update jslib (9957125 -> 5d874d0) (#521) * Updated change password flow to match web * Updated callout style Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Oscar Hinton <hinton.oscar@gmail.com> Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Oscar Hinton <hinton.oscar@gmail.com>
2020-08-21 15:50:36 +02:00
{ provide: CryptoFunctionServiceAbstraction, useValue: cryptoFunctionService },
{ provide: NativeMessagingService, useValue: nativeMessagingService },
2018-01-24 20:59:03 +01:00
{
provide: APP_INITIALIZER,
useFactory: initFactory,
2018-02-16 21:46:37 +01:00
deps: [],
2018-01-24 21:22:13 +01:00
multi: true,
},
2018-08-02 15:26:50 +02:00
{
provide: LOCALE_ID,
useFactory: () => i18nService.translationLocale,
deps: [],
},
2018-01-23 05:37:36 +01:00
],
})
export class ServicesModule {
}