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,
|
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-01-23 19:59:01 +01:00
|
|
|
import { DesktopMessagingService } from '../../services/desktopMessaging.service';
|
|
|
|
import { DesktopPlatformUtilsService } from '../../services/desktopPlatformUtils.service';
|
2018-01-23 21:08:57 +01:00
|
|
|
import { DesktopSecureStorageService } from '../../services/desktopSecureStorage.service';
|
2018-02-08 16:37:54 +01:00
|
|
|
import { DesktopStorageService } from '../../services/desktopStorage.service';
|
2018-01-24 20:59:03 +01:00
|
|
|
import { I18nService } from '../../services/i18n.service';
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2018-02-08 17:12:25 +01:00
|
|
|
import { AuthGuardService } from './auth-guard.service';
|
2018-02-08 18:24:17 +01:00
|
|
|
import { BroadcasterService } from './broadcaster.service';
|
2018-01-31 05:34:45 +01:00
|
|
|
import { ValidationService } from './validation.service';
|
|
|
|
|
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';
|
|
|
|
|
2018-01-23 22:58:32 +01:00
|
|
|
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-02-08 18:24:17 +01:00
|
|
|
const broadcasterService = new BroadcasterService();
|
|
|
|
const messagingService = new DesktopMessagingService(broadcasterService);
|
2018-01-23 05:37:36 +01:00
|
|
|
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,
|
2018-01-27 04:39:45 +01:00
|
|
|
apiService, storageService, i18nService);
|
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-02-10 04:47:53 +01:00
|
|
|
cryptoService, platformUtilsService, storageService, messagingService);
|
2018-01-23 05:37:36 +01:00
|
|
|
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);
|
2018-02-02 04:59:04 +01:00
|
|
|
const authService = new AuthService(cryptoService, apiService,
|
|
|
|
userService, tokenService, appIdService, i18nService, platformUtilsService, constantsService,
|
2018-01-23 05:37:36 +01:00
|
|
|
messagingService);
|
|
|
|
|
2018-01-26 16:50:06 +01:00
|
|
|
const analytics = new Analytics(window, null, platformUtilsService, storageService, appIdService);
|
2018-01-23 22:58:32 +01:00
|
|
|
containerService.attachToWindow(window);
|
|
|
|
environmentService.setUrlsFromStorage().then(() => {
|
|
|
|
return syncService.fullSync(true);
|
|
|
|
});
|
|
|
|
|
2018-02-08 16:37:54 +01:00
|
|
|
function initFactory(i18n: I18nService, platformUtils: DesktopPlatformUtilsService): Function {
|
2018-01-31 02:03:41 +01:00
|
|
|
return async () => {
|
|
|
|
await i18n.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-08 16:37:54 +01:00
|
|
|
htmlEl.classList.add('os_' + platformUtils.getDeviceString());
|
2018-01-31 02:03:41 +01:00
|
|
|
htmlEl.classList.add('locale_' + i18n.translationLocale);
|
|
|
|
};
|
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-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: UtilsServiceAbstraction, useValue: utilsService },
|
|
|
|
{ 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-01-24 20:59:03 +01:00
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
|
|
|
useFactory: initFactory,
|
2018-01-31 02:03:41 +01:00
|
|
|
deps: [
|
2018-02-08 16:37:54 +01:00
|
|
|
I18nServiceAbstraction,
|
2018-01-31 02:03:41 +01:00
|
|
|
PlatformUtilsServiceAbstraction,
|
|
|
|
],
|
2018-01-24 21:22:13 +01:00
|
|
|
multi: true,
|
|
|
|
},
|
2018-01-23 05:37:36 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
export class ServicesModule {
|
|
|
|
}
|