2018-01-23 22:58:32 +01:00
|
|
|
import { webFrame } from 'electron';
|
2018-01-23 19:59:01 +01:00
|
|
|
|
2018-01-24 20:59:03 +01:00
|
|
|
import {
|
|
|
|
APP_INITIALIZER,
|
|
|
|
NgModule
|
|
|
|
} 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
|
|
|
|
|
|
|
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,
|
|
|
|
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';
|
|
|
|
|
2018-01-23 22:58:32 +01:00
|
|
|
webFrame.registerURLSchemeAsPrivileged('file');
|
|
|
|
|
2018-01-24 20:59:03 +01:00
|
|
|
const i18nService = new I18nService(window, './_locales');
|
2018-01-23 05:37:36 +01:00
|
|
|
const utilsService = new UtilsService();
|
|
|
|
const platformUtilsService = new DesktopPlatformUtilsService();
|
|
|
|
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-24 20:59:03 +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-23 22:58:32 +01:00
|
|
|
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 },
|
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-24 20:59:03 +01:00
|
|
|
{ provide: I18nService, useValue: i18nService },
|
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
|
|
|
useFactory: initFactory,
|
|
|
|
deps: [I18nService],
|
|
|
|
multi: true
|
|
|
|
}
|
2018-01-23 05:37:36 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
export class ServicesModule {
|
|
|
|
}
|