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-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 { ElectronRendererSecureStorageService } from 'jslib/electron/services/electronRendererSecureStorage.service';
|
|
|
|
import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service';
|
|
|
|
import { isDev } from 'jslib/electron/utils';
|
2018-02-16 21:06:54 +01:00
|
|
|
|
2018-04-25 05:23:10 +02:00
|
|
|
import { DesktopRendererMessagingService } from '../services/desktopRendererMessaging.service';
|
|
|
|
import { I18nService } from '../services/i18n.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';
|
|
|
|
|
2018-02-19 19:16:12 +01:00
|
|
|
import { ApiService } from 'jslib/services/api.service';
|
|
|
|
import { AppIdService } from 'jslib/services/appId.service';
|
2018-02-28 16:53:18 +01:00
|
|
|
import { AuditService } from 'jslib/services/audit.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
|
|
|
import { FolderService } from 'jslib/services/folder.service';
|
|
|
|
import { LockService } from 'jslib/services/lock.service';
|
|
|
|
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
|
|
|
|
import { SettingsService } from 'jslib/services/settings.service';
|
|
|
|
import { StateService } from 'jslib/services/state.service';
|
|
|
|
import { SyncService } from 'jslib/services/sync.service';
|
|
|
|
import { TokenService } from 'jslib/services/token.service';
|
|
|
|
import { TotpService } from 'jslib/services/totp.service';
|
|
|
|
import { UserService } from 'jslib/services/user.service';
|
2018-04-22 05:14:58 +02:00
|
|
|
import { WebCryptoFunctionService } from 'jslib/services/webCryptoFunction.service';
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2018-02-19 19:16:12 +01:00
|
|
|
import { ApiService as ApiServiceAbstraction } from 'jslib/abstractions/api.service';
|
|
|
|
import { AppIdService as AppIdServiceAbstraction } from 'jslib/abstractions/appId.service';
|
2018-02-28 16:53:18 +01:00
|
|
|
import { AuditService as AuditServiceAbstraction } from 'jslib/abstractions/audit.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
import { EnvironmentService as EnvironmentServiceAbstraction } from 'jslib/abstractions/environment.service';
|
|
|
|
import { FolderService as FolderServiceAbstraction } from 'jslib/abstractions/folder.service';
|
|
|
|
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { LockService as LockServiceAbstraction } from 'jslib/abstractions/lock.service';
|
2018-02-24 05:12:06 +01:00
|
|
|
import { LogService as LogServiceAbstraction } from 'jslib/abstractions/log.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
import { MessagingService as MessagingServiceAbstraction } from 'jslib/abstractions/messaging.service';
|
2018-01-23 05:37:36 +01:00
|
|
|
import {
|
|
|
|
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
2018-02-19 19:16:12 +01:00
|
|
|
} from 'jslib/abstractions/passwordGeneration.service';
|
|
|
|
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from 'jslib/abstractions/platformUtils.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';
|
|
|
|
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';
|
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-04-24 22:30:47 +02:00
|
|
|
const platformUtilsService = new ElectronPlatformUtilsService(i18nService, true);
|
2018-02-08 18:24:17 +01:00
|
|
|
const broadcasterService = new BroadcasterService();
|
2018-02-11 05:24:22 +01:00
|
|
|
const messagingService = new DesktopRendererMessagingService(broadcasterService);
|
2018-04-24 22:30:47 +02:00
|
|
|
const storageService: StorageServiceAbstraction = new ElectronStorageService();
|
|
|
|
const secureStorageService: StorageServiceAbstraction = new ElectronRendererSecureStorageService();
|
2018-04-22 05:14:58 +02:00
|
|
|
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,
|
|
|
|
platformUtilsService);
|
|
|
|
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-02-16 21:09:35 +01:00
|
|
|
(expired: boolean) => messagingService.send('logout', { expired: expired }));
|
2018-01-23 05:37:36 +01:00
|
|
|
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,
|
2018-04-23 19:04:02 +02:00
|
|
|
apiService, storageService, i18nService, platformUtilsService);
|
2018-01-23 05:37:36 +01:00
|
|
|
const folderService = new FolderService(cryptoService, userService,
|
2018-01-27 04:39:45 +01:00
|
|
|
() => i18nService.t('noneFolder'), apiService, storageService, i18nService);
|
|
|
|
const collectionService = new CollectionService(cryptoService, userService, storageService, i18nService);
|
2018-01-23 05:37:36 +01:00
|
|
|
const lockService = new LockService(cipherService, folderService, collectionService,
|
2018-03-09 19:04:30 +01:00
|
|
|
cryptoService, platformUtilsService, storageService, messagingService, () => { /* do nothing */ });
|
2018-01-23 05:37:36 +01:00
|
|
|
const syncService = new SyncService(userService, apiService, settingsService,
|
|
|
|
folderService, cipherService, cryptoService, collectionService,
|
2018-02-16 21:09:35 +01:00
|
|
|
storageService, messagingService, (expired: boolean) => messagingService.send('logout', { expired: expired }));
|
2018-01-23 05:37:36 +01:00
|
|
|
const passwordGenerationService = new PasswordGenerationService(cryptoService, storageService);
|
2018-04-22 05:56:18 +02:00
|
|
|
const totpService = new TotpService(storageService, cryptoFunctionService);
|
2018-01-23 05:37:36 +01:00
|
|
|
const containerService = new ContainerService(cryptoService, platformUtilsService);
|
2018-02-02 04:59:04 +01:00
|
|
|
const authService = new AuthService(cryptoService, apiService,
|
2018-04-19 20:10:28 +02:00
|
|
|
userService, tokenService, appIdService, i18nService, platformUtilsService, messagingService);
|
2018-04-22 05:56:18 +02:00
|
|
|
const auditService = new AuditService(cryptoFunctionService);
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2018-02-16 21:06:54 +01:00
|
|
|
const analytics = new Analytics(window, () => isDev(), platformUtilsService, storageService, appIdService);
|
2018-01-23 22:58:32 +01:00
|
|
|
containerService.attachToWindow(window);
|
|
|
|
environmentService.setUrlsFromStorage().then(() => {
|
|
|
|
return syncService.fullSync(true);
|
|
|
|
});
|
|
|
|
|
2018-04-06 18:25:22 +02:00
|
|
|
export function initFactory(): Function {
|
2018-01-31 02:03:41 +01:00
|
|
|
return async () => {
|
2018-02-16 21:46:37 +01:00
|
|
|
await i18nService.init();
|
2018-02-02 04:59:04 +01:00
|
|
|
await authService.init();
|
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-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,
|
2018-02-28 16:53:18 +01:00
|
|
|
{ provide: AuditServiceAbstraction, useValue: auditService },
|
2018-01-23 05:37:36 +01:00
|
|
|
{ provide: AuthServiceAbstraction, useValue: authService },
|
2018-01-23 22:58:32 +01:00
|
|
|
{ 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: 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 },
|
2018-02-10 04:47:53 +01:00
|
|
|
{ provide: LockServiceAbstraction, useValue: lockService },
|
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-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-01-23 05:37:36 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
export class ServicesModule {
|
|
|
|
}
|