2022-04-29 09:48:44 +02:00
|
|
|
import { Inject, Injectable } from "@angular/core";
|
|
|
|
|
2022-09-07 22:23:32 +02:00
|
|
|
import { WINDOW } from "@bitwarden/angular/services/injection-tokens";
|
2022-06-23 13:36:05 +02:00
|
|
|
import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { EnvironmentService as EnvironmentServiceAbstraction } from "@bitwarden/common/abstractions/environment.service";
|
2022-12-06 14:47:42 +01:00
|
|
|
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service";
|
|
|
|
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService as StateServiceAbstraction } from "@bitwarden/common/abstractions/state.service";
|
2022-08-29 20:14:59 +02:00
|
|
|
import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/abstractions/twoFactor.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ContainerService } from "@bitwarden/common/services/container.service";
|
2022-12-06 14:47:42 +01:00
|
|
|
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service";
|
2022-04-29 09:48:44 +02:00
|
|
|
|
2022-12-21 05:27:00 +01:00
|
|
|
import { DesktopI18nServiceImplementation } from "../../services/desktop-i18n.service.implementation";
|
2022-11-24 15:05:45 +01:00
|
|
|
import { NativeMessagingService } from "../../services/native-messaging.service";
|
2022-04-29 09:48:44 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class InitService {
|
|
|
|
constructor(
|
|
|
|
@Inject(WINDOW) private win: Window,
|
|
|
|
private environmentService: EnvironmentServiceAbstraction,
|
|
|
|
private syncService: SyncServiceAbstraction,
|
|
|
|
private vaultTimeoutService: VaultTimeoutServiceAbstraction,
|
|
|
|
private i18nService: I18nServiceAbstraction,
|
2022-12-06 14:47:42 +01:00
|
|
|
private eventUploadService: EventUploadServiceAbstraction,
|
2022-04-29 09:48:44 +02:00
|
|
|
private twoFactorService: TwoFactorServiceAbstraction,
|
|
|
|
private notificationsService: NotificationsServiceAbstraction,
|
|
|
|
private platformUtilsService: PlatformUtilsServiceAbstraction,
|
|
|
|
private stateService: StateServiceAbstraction,
|
|
|
|
private cryptoService: CryptoServiceAbstraction,
|
2022-06-23 13:36:05 +02:00
|
|
|
private nativeMessagingService: NativeMessagingService,
|
2022-09-02 03:15:19 +02:00
|
|
|
private themingService: AbstractThemingService,
|
2022-10-27 23:38:54 +02:00
|
|
|
private encryptService: EncryptService
|
2022-04-29 09:48:44 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
return async () => {
|
|
|
|
this.nativeMessagingService.init();
|
|
|
|
await this.stateService.init();
|
|
|
|
await this.environmentService.setUrlsFromStorage();
|
|
|
|
this.syncService.fullSync(true);
|
|
|
|
(this.vaultTimeoutService as VaultTimeoutService).init(true);
|
|
|
|
const locale = await this.stateService.getLocale();
|
2022-12-21 05:27:00 +01:00
|
|
|
await (this.i18nService as DesktopI18nServiceImplementation).init(locale);
|
2022-12-06 14:47:42 +01:00
|
|
|
(this.eventUploadService as EventUploadService).init(true);
|
2022-04-29 09:48:44 +02:00
|
|
|
this.twoFactorService.init();
|
|
|
|
setTimeout(() => this.notificationsService.init(), 3000);
|
|
|
|
const htmlEl = this.win.document.documentElement;
|
|
|
|
htmlEl.classList.add("os_" + this.platformUtilsService.getDeviceString());
|
2022-06-23 13:36:05 +02:00
|
|
|
await this.themingService.monitorThemeChanges();
|
2022-04-29 09:48:44 +02:00
|
|
|
let installAction = null;
|
|
|
|
const installedVersion = await this.stateService.getInstalledVersion();
|
|
|
|
const currentVersion = await this.platformUtilsService.getApplicationVersion();
|
|
|
|
if (installedVersion == null) {
|
|
|
|
installAction = "install";
|
|
|
|
} else if (installedVersion !== currentVersion) {
|
|
|
|
installAction = "update";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (installAction != null) {
|
|
|
|
await this.stateService.setInstalledVersion(currentVersion);
|
|
|
|
}
|
|
|
|
|
2022-09-02 03:15:19 +02:00
|
|
|
const containerService = new ContainerService(this.cryptoService, this.encryptService);
|
2022-04-29 09:48:44 +02:00
|
|
|
containerService.attachToGlobal(this.win);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|