2018-01-24 20:59:03 +01:00
|
|
|
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { ElectronLogService } from "jslib-electron/services/electronLog.service";
|
2021-08-27 15:30:44 +02:00
|
|
|
import { ElectronPlatformUtilsService } from "jslib-electron/services/electronPlatformUtils.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { ElectronRendererMessagingService } from "jslib-electron/services/electronRendererMessaging.service";
|
|
|
|
import { ElectronRendererSecureStorageService } from "jslib-electron/services/electronRendererSecureStorage.service";
|
|
|
|
import { ElectronRendererStorageService } from "jslib-electron/services/electronRendererStorage.service";
|
2019-07-24 20:48:08 +02:00
|
|
|
|
2018-04-25 05:26:50 +02:00
|
|
|
import { I18nService } from "../services/i18n.service";
|
2021-12-15 23:32:00 +01:00
|
|
|
import { LoginGuardService } from "../services/loginGuard.service";
|
2020-10-12 21:18:28 +02:00
|
|
|
import { NativeMessagingService } from "../services/nativeMessaging.service";
|
2021-08-27 15:30:44 +02:00
|
|
|
import { PasswordRepromptService } from "../services/passwordReprompt.service";
|
2022-01-12 17:37:23 +01:00
|
|
|
import { StateService } from "../services/state.service";
|
|
|
|
|
2021-12-15 23:32:00 +01:00
|
|
|
import { SearchBarService } from "./layout/search/search-bar.service";
|
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";
|
2018-01-31 05:34:45 +01:00
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { AuthService } from "jslib-common/services/auth.service";
|
|
|
|
import { ContainerService } from "jslib-common/services/container.service";
|
|
|
|
import { EventService } from "jslib-common/services/event.service";
|
|
|
|
import { SystemService } from "jslib-common/services/system.service";
|
|
|
|
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2021-06-15 20:40:34 +02:00
|
|
|
import { ElectronCryptoService } from "jslib-electron/services/electronCrypto.service";
|
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { AuthService as AuthServiceAbstraction } from "jslib-common/abstractions/auth.service";
|
2021-12-06 12:03:02 +01:00
|
|
|
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";
|
|
|
|
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";
|
2018-01-23 05:37:36 +01:00
|
|
|
|
2022-01-19 17:00:28 +01:00
|
|
|
import { Account } from "../models/account";
|
|
|
|
|
|
|
|
import { AccountFactory } from "jslib-common/models/domain/account";
|
|
|
|
|
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,
|
2021-12-06 12:03:02 +01:00
|
|
|
authService: AuthService,
|
|
|
|
notificationsService: NotificationsServiceAbstraction,
|
|
|
|
platformUtilsService: PlatformUtilsServiceAbstraction,
|
|
|
|
stateService: StateServiceAbstraction,
|
|
|
|
cryptoService: CryptoServiceAbstraction
|
|
|
|
): Function {
|
2018-01-31 02:03:41 +01:00
|
|
|
return async () => {
|
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);
|
2018-10-04 18:05:32 +02:00
|
|
|
authService.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,
|
|
|
|
AuthServiceAbstraction,
|
|
|
|
NotificationsServiceAbstraction,
|
|
|
|
PlatformUtilsServiceAbstraction,
|
|
|
|
StateServiceAbstraction,
|
|
|
|
CryptoServiceAbstraction,
|
|
|
|
],
|
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,
|
|
|
|
new AccountFactory(Account)
|
|
|
|
),
|
2022-01-12 17:37:23 +01:00
|
|
|
deps: [
|
|
|
|
StorageServiceAbstraction,
|
|
|
|
"SECURE_STORAGE",
|
|
|
|
LogServiceAbstraction,
|
|
|
|
StateMigrationServiceAbstraction,
|
|
|
|
],
|
|
|
|
},
|
2018-01-23 05:37:36 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
export class ServicesModule {}
|