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';
|
2018-04-25 15:01:04 +02:00
|
|
|
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';
|
2020-10-12 21:18:28 +02:00
|
|
|
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';
|
|
|
|
|
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';
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
import { FolderService } from 'jslib/services/folder.service';
|
2018-08-20 22:23:55 +02:00
|
|
|
import { NotificationsService } from 'jslib/services/notifications.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2020-11-18 22:13:05 +01:00
|
|
|
import { SendService } from 'jslib/services/send.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
import { TokenService } from 'jslib/services/token.service';
|
|
|
|
import { TotpService } from 'jslib/services/totp.service';
|
|
|
|
import { UserService } from 'jslib/services/user.service';
|
2020-04-01 17:18:36 +02:00
|
|
|
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
|
|
|
|
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';
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
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,
|
2018-02-19 19:16:12 +01:00
|
|
|
} 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';
|
2020-11-18 22:13:05 +01:00
|
|
|
import { SendService as SendServiceAbstraction } from 'jslib/abstractions/send.service';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2018-02-19 19:16:12 +01:00
|
|
|
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';
|
2020-04-01 17:18:36 +02:00
|
|
|
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();
|
2018-04-25 15:01:04 +02:00
|
|
|
const messagingService = new ElectronRendererMessagingService(broadcasterService);
|
2019-03-12 03:37:13 +01:00
|
|
|
const storageService: StorageServiceAbstraction = new ElectronStorageService(remote.app.getPath('userData'));
|
2020-07-23 19:32:36 +02:00
|
|
|
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);
|
2020-11-24 21:01:34 +01:00
|
|
|
const cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService,
|
|
|
|
platformUtilsService, logService);
|
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-11-24 21:01:34 +01:00
|
|
|
searchService = new SearchService(cipherService, logService);
|
2020-11-18 22:13:05 +01:00
|
|
|
const sendService = new SendService(cryptoService, userService, apiService, storageService,
|
|
|
|
i18nService, cryptoFunctionService);
|
2020-01-31 04:11:16 +01:00
|
|
|
const policyService = new PolicyService(userService, storageService);
|
2020-04-01 17:18:36 +02:00
|
|
|
const vaultTimeoutService = new VaultTimeoutService(cipherService, folderService, collectionService,
|
2020-04-06 20:00:10 +02:00
|
|
|
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,
|
2020-11-18 22:13:05 +01:00
|
|
|
sendService, async (expired: boolean) => messagingService.send('logout', { expired: expired }));
|
2020-02-27 19:13:55 +01:00
|
|
|
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);
|
2020-07-23 19:32:36 +02:00
|
|
|
const authService = new AuthService(cryptoService, apiService, userService, tokenService, appIdService,
|
2020-11-24 21:01:34 +01:00
|
|
|
i18nService, platformUtilsService, messagingService, vaultTimeoutService, logService);
|
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,
|
2020-11-24 21:01:34 +01:00
|
|
|
apiService, vaultTimeoutService, async () => messagingService.send('logout', { expired: true }), logService);
|
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);
|
2020-04-01 17:18:36 +02:00
|
|
|
const systemService = new SystemService(storageService, vaultTimeoutService, messagingService, platformUtilsService,
|
|
|
|
null);
|
2020-11-30 14:58:52 +01:00
|
|
|
const nativeMessagingService = new NativeMessagingService(cryptoFunctionService, cryptoService, platformUtilsService,
|
2020-12-16 17:25:30 +01:00
|
|
|
logService, i18nService, userService, messagingService, vaultTimeoutService);
|
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);
|
2018-01-23 22:58:32 +01:00
|
|
|
|
2018-04-06 18:25:22 +02:00
|
|
|
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);
|
2020-04-01 17:18:36 +02:00
|
|
|
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,
|
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 },
|
2020-08-19 16:03:14 +02:00
|
|
|
{ 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 },
|
2020-04-01 17:18:36 +02:00
|
|
|
{ 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 },
|
2020-11-18 22:13:05 +01:00
|
|
|
{ provide: SendServiceAbstraction, useValue: sendService },
|
2020-08-21 15:50:36 +02:00
|
|
|
{ provide: CryptoFunctionServiceAbstraction, useValue: cryptoFunctionService },
|
2020-10-12 21:18:28 +02:00
|
|
|
{ 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 {
|
|
|
|
}
|