2018-01-24 20:59:03 +01:00
|
|
|
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2021-12-06 12:03:02 +01:00
|
|
|
import { JslibServicesModule } from "jslib-angular/services/jslib-services.module";
|
|
|
|
import { BroadcasterService as BroadcasterServiceAbstraction } from "jslib-common/abstractions/broadcaster.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { CryptoService as CryptoServiceAbstraction } from "jslib-common/abstractions/crypto.service";
|
|
|
|
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "jslib-common/abstractions/cryptoFunction.service";
|
|
|
|
import { EnvironmentService as EnvironmentServiceAbstraction } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { EventService as EventServiceAbstraction } from "jslib-common/abstractions/event.service";
|
|
|
|
import { I18nService as I18nServiceAbstraction } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { LogService as LogServiceAbstraction } from "jslib-common/abstractions/log.service";
|
|
|
|
import { MessagingService as MessagingServiceAbstraction } from "jslib-common/abstractions/messaging.service";
|
|
|
|
import { NotificationsService as NotificationsServiceAbstraction } from "jslib-common/abstractions/notifications.service";
|
|
|
|
import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "jslib-common/abstractions/passwordReprompt.service";
|
|
|
|
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { StateService as StateServiceAbstraction } from "jslib-common/abstractions/state.service";
|
2022-01-12 17:37:23 +01:00
|
|
|
import { StateMigrationService as StateMigrationServiceAbstraction } from "jslib-common/abstractions/stateMigration.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { StorageService as StorageServiceAbstraction } from "jslib-common/abstractions/storage.service";
|
|
|
|
import { SyncService as SyncServiceAbstraction } from "jslib-common/abstractions/sync.service";
|
|
|
|
import { SystemService as SystemServiceAbstraction } from "jslib-common/abstractions/system.service";
|
2022-02-08 00:26:53 +01:00
|
|
|
import { TwoFactorService as TwoFactorServiceAbstraction } from "jslib-common/abstractions/twoFactor.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service";
|
2021-10-04 22:30:09 +02:00
|
|
|
import { ThemeType } from "jslib-common/enums/themeType";
|
2022-02-24 20:50:19 +01:00
|
|
|
import { StateFactory } from "jslib-common/factories/stateFactory";
|
|
|
|
import { GlobalState } from "jslib-common/models/domain/globalState";
|
|
|
|
import { ContainerService } from "jslib-common/services/container.service";
|
|
|
|
import { EventService } from "jslib-common/services/event.service";
|
|
|
|
import { StateMigrationService } from "jslib-common/services/stateMigration.service";
|
|
|
|
import { SystemService } from "jslib-common/services/system.service";
|
|
|
|
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
|
|
|
|
import { ElectronCryptoService } from "jslib-electron/services/electronCrypto.service";
|
|
|
|
import { ElectronLogService } from "jslib-electron/services/electronLog.service";
|
|
|
|
import { ElectronPlatformUtilsService } from "jslib-electron/services/electronPlatformUtils.service";
|
|
|
|
import { ElectronRendererMessagingService } from "jslib-electron/services/electronRendererMessaging.service";
|
|
|
|
import { ElectronRendererSecureStorageService } from "jslib-electron/services/electronRendererSecureStorage.service";
|
|
|
|
import { ElectronRendererStorageService } from "jslib-electron/services/electronRendererStorage.service";
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2022-01-19 17:00:28 +01:00
|
|
|
import { Account } from "../models/account";
|
2022-02-24 20:50:19 +01:00
|
|
|
import { I18nService } from "../services/i18n.service";
|
|
|
|
import { LoginGuardService } from "../services/loginGuard.service";
|
|
|
|
import { NativeMessagingService } from "../services/nativeMessaging.service";
|
|
|
|
import { PasswordRepromptService } from "../services/passwordReprompt.service";
|
|
|
|
import { StateService } from "../services/state.service";
|
2022-01-19 17:00:28 +01:00
|
|
|
|
2022-02-24 20:50:19 +01:00
|
|
|
import { SearchBarService } from "./layout/search/search-bar.service";
|
2022-01-19 17:00:28 +01:00
|
|
|
|
2021-12-06 12:03:02 +01:00
|
|
|
export function initFactory(
|
|
|
|
window: Window,
|
|
|
|
environmentService: EnvironmentServiceAbstraction,
|
|
|
|
syncService: SyncServiceAbstraction,
|
|
|
|
vaultTimeoutService: VaultTimeoutService,
|
2021-12-15 23:32:00 +01:00
|
|
|
i18nService: I18nService,
|
|
|
|
eventService: EventService,
|
2022-02-08 00:26:53 +01:00
|
|
|
twoFactorService: TwoFactorServiceAbstraction,
|
2021-12-06 12:03:02 +01:00
|
|
|
notificationsService: NotificationsServiceAbstraction,
|
|
|
|
platformUtilsService: PlatformUtilsServiceAbstraction,
|
|
|
|
stateService: StateServiceAbstraction,
|
2022-01-24 16:10:32 +01:00
|
|
|
cryptoService: CryptoServiceAbstraction,
|
|
|
|
nativeMessagingService: NativeMessagingService
|
2022-02-24 20:50:19 +01:00
|
|
|
): () => Promise<void> {
|
2018-01-31 02:03:41 +01:00
|
|
|
return async () => {
|
2022-01-24 16:10:32 +01:00
|
|
|
nativeMessagingService.init();
|
2021-12-15 23:32:00 +01:00
|
|
|
await stateService.init();
|
2018-08-20 22:23:55 +02:00
|
|
|
await environmentService.setUrlsFromStorage();
|
|
|
|
syncService.fullSync(true);
|
2021-12-15 23:32:00 +01:00
|
|
|
await vaultTimeoutService.init(true);
|
|
|
|
const locale = await stateService.getLocale();
|
2018-04-25 05:53:20 +02:00
|
|
|
await i18nService.init(locale);
|
2019-07-09 19:11:10 +02:00
|
|
|
eventService.init(true);
|
2022-02-08 00:26:53 +01:00
|
|
|
twoFactorService.init();
|
2021-07-23 23:15:32 +02:00
|
|
|
setTimeout(() => notificationsService.init(), 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);
|
2021-10-04 22:30:09 +02:00
|
|
|
const theme = await platformUtilsService.getEffectiveTheme();
|
2018-05-30 21:39:20 +02:00
|
|
|
htmlEl.classList.add("theme_" + theme);
|
2021-10-04 22:30:09 +02:00
|
|
|
platformUtilsService.onDefaultSystemThemeChange(async (sysTheme) => {
|
2021-12-15 23:32:00 +01:00
|
|
|
const bwTheme = await stateService.getTheme();
|
2021-10-04 22:30:09 +02:00
|
|
|
if (bwTheme == null || bwTheme === ThemeType.System) {
|
|
|
|
htmlEl.classList.remove("theme_" + ThemeType.Light, "theme_" + ThemeType.Dark);
|
|
|
|
htmlEl.classList.add("theme_" + sysTheme);
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
|
|
|
});
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
let installAction = null;
|
|
|
|
const installedVersion = await stateService.getInstalledVersion();
|
2021-10-04 22:30:09 +02:00
|
|
|
const currentVersion = await platformUtilsService.getApplicationVersion();
|
|
|
|
if (installedVersion == null) {
|
|
|
|
installAction = "install";
|
|
|
|
} else if (installedVersion !== currentVersion) {
|
|
|
|
installAction = "update";
|
|
|
|
}
|
|
|
|
|
2018-02-16 21:46:37 +01:00
|
|
|
if (installAction != null) {
|
2021-12-15 23:32:00 +01:00
|
|
|
await stateService.setInstalledVersion(currentVersion);
|
2018-02-16 21:46:37 +01:00
|
|
|
}
|
|
|
|
|
2021-12-06 12:03:02 +01:00
|
|
|
const containerService = new ContainerService(cryptoService);
|
|
|
|
containerService.attachToGlobal(window);
|
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({
|
2021-12-06 12:03:02 +01:00
|
|
|
imports: [JslibServicesModule],
|
2018-01-23 05:37:36 +01:00
|
|
|
declarations: [],
|
|
|
|
providers: [
|
2018-01-24 20:59:03 +01:00
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
|
|
|
useFactory: initFactory,
|
2021-12-06 12:03:02 +01:00
|
|
|
deps: [
|
|
|
|
"WINDOW",
|
|
|
|
EnvironmentServiceAbstraction,
|
|
|
|
SyncServiceAbstraction,
|
|
|
|
VaultTimeoutServiceAbstraction,
|
|
|
|
I18nServiceAbstraction,
|
|
|
|
EventServiceAbstraction,
|
2022-02-08 00:26:53 +01:00
|
|
|
TwoFactorServiceAbstraction,
|
2021-12-06 12:03:02 +01:00
|
|
|
NotificationsServiceAbstraction,
|
|
|
|
PlatformUtilsServiceAbstraction,
|
|
|
|
StateServiceAbstraction,
|
|
|
|
CryptoServiceAbstraction,
|
2022-01-24 16:10:32 +01:00
|
|
|
NativeMessagingService,
|
2021-12-06 12:03:02 +01:00
|
|
|
],
|
2018-01-24 21:22:13 +01:00
|
|
|
multi: true,
|
|
|
|
},
|
2021-12-06 12:03:02 +01:00
|
|
|
{ provide: LogServiceAbstraction, useClass: ElectronLogService, deps: [] },
|
|
|
|
{
|
|
|
|
provide: PlatformUtilsServiceAbstraction,
|
|
|
|
useFactory: (
|
|
|
|
i18nService: I18nServiceAbstraction,
|
|
|
|
messagingService: MessagingServiceAbstraction,
|
2021-12-15 23:32:00 +01:00
|
|
|
stateService: StateServiceAbstraction
|
|
|
|
) => new ElectronPlatformUtilsService(i18nService, messagingService, true, stateService),
|
|
|
|
deps: [I18nServiceAbstraction, MessagingServiceAbstraction, StateServiceAbstraction],
|
2021-12-06 12:03:02 +01:00
|
|
|
},
|
2018-08-02 15:26:50 +02:00
|
|
|
{
|
2021-12-06 12:03:02 +01:00
|
|
|
provide: I18nServiceAbstraction,
|
|
|
|
useFactory: (window: Window) => new I18nService(window.navigator.language, "./locales"),
|
|
|
|
deps: ["WINDOW"],
|
2018-08-02 15:26:50 +02:00
|
|
|
},
|
2021-12-06 12:03:02 +01:00
|
|
|
{
|
|
|
|
provide: MessagingServiceAbstraction,
|
|
|
|
useClass: ElectronRendererMessagingService,
|
|
|
|
deps: [BroadcasterServiceAbstraction],
|
|
|
|
},
|
|
|
|
{ provide: StorageServiceAbstraction, useClass: ElectronRendererStorageService },
|
|
|
|
{ provide: "SECURE_STORAGE", useClass: ElectronRendererSecureStorageService },
|
|
|
|
{
|
|
|
|
provide: CryptoServiceAbstraction,
|
|
|
|
useClass: ElectronCryptoService,
|
|
|
|
deps: [
|
|
|
|
CryptoFunctionServiceAbstraction,
|
|
|
|
PlatformUtilsServiceAbstraction,
|
|
|
|
LogServiceAbstraction,
|
2021-12-15 23:32:00 +01:00
|
|
|
StateServiceAbstraction,
|
2021-12-06 12:03:02 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: SystemServiceAbstraction,
|
2022-01-22 21:24:12 +01:00
|
|
|
useFactory: (
|
|
|
|
messagingService: MessagingServiceAbstraction,
|
|
|
|
platformUtilsService: PlatformUtilsServiceAbstraction,
|
|
|
|
stateService: StateServiceAbstraction
|
|
|
|
) => new SystemService(messagingService, platformUtilsService, null, stateService),
|
|
|
|
deps: [MessagingServiceAbstraction, PlatformUtilsServiceAbstraction, StateServiceAbstraction],
|
2021-12-06 12:03:02 +01:00
|
|
|
},
|
|
|
|
{ provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService },
|
|
|
|
NativeMessagingService,
|
2021-12-15 23:32:00 +01:00
|
|
|
SearchBarService,
|
|
|
|
{
|
|
|
|
provide: LoginGuardService,
|
|
|
|
useClass: LoginGuardService,
|
|
|
|
deps: [StateServiceAbstraction, PlatformUtilsServiceAbstraction, I18nServiceAbstraction],
|
|
|
|
},
|
2022-01-12 17:37:23 +01:00
|
|
|
{
|
|
|
|
provide: StateServiceAbstraction,
|
2022-01-19 17:00:28 +01:00
|
|
|
useFactory: (
|
|
|
|
storageService: StorageServiceAbstraction,
|
|
|
|
secureStorageService: StorageServiceAbstraction,
|
|
|
|
logService: LogServiceAbstraction,
|
|
|
|
stateMigrationService: StateMigrationServiceAbstraction
|
|
|
|
) =>
|
|
|
|
new StateService(
|
|
|
|
storageService,
|
|
|
|
secureStorageService,
|
|
|
|
logService,
|
|
|
|
stateMigrationService,
|
2022-02-01 00:00:37 +01:00
|
|
|
new StateFactory(GlobalState, Account)
|
2022-01-19 17:00:28 +01:00
|
|
|
),
|
2022-01-12 17:37:23 +01:00
|
|
|
deps: [
|
|
|
|
StorageServiceAbstraction,
|
|
|
|
"SECURE_STORAGE",
|
|
|
|
LogServiceAbstraction,
|
|
|
|
StateMigrationServiceAbstraction,
|
|
|
|
],
|
|
|
|
},
|
2022-02-09 18:42:16 +01:00
|
|
|
{
|
|
|
|
provide: StateMigrationServiceAbstraction,
|
|
|
|
useFactory: (
|
|
|
|
storageService: StorageServiceAbstraction,
|
|
|
|
secureStorageService: StorageServiceAbstraction
|
|
|
|
) =>
|
|
|
|
new StateMigrationService(
|
|
|
|
storageService,
|
|
|
|
secureStorageService,
|
|
|
|
new StateFactory(GlobalState, Account)
|
|
|
|
),
|
|
|
|
deps: [StorageServiceAbstraction, "SECURE_STORAGE"],
|
|
|
|
},
|
2018-01-23 05:37:36 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
export class ServicesModule {}
|