From b2374acc7f6bda4070b31e6fcc06b9b974918c15 Mon Sep 17 00:00:00 2001 From: Todd Martin <106564991+trmartin4@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:10:47 -0400 Subject: [PATCH] [PM-3020] Change initialization of EnvironmentService to default to uninitialized (#5830) * Set initialized to false on construction of the EnvironmentService * Add initialization on browser and desktop. * Added comments. --- apps/browser/src/background/main.background.ts | 3 +++ apps/desktop/src/app/services/init.service.ts | 3 +++ apps/web/src/app/core/init.service.ts | 5 ++--- libs/common/src/platform/services/environment.service.ts | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index f816624097..62fb1d85d5 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -676,6 +676,9 @@ export default class MainBackground { return new Promise((resolve) => { setTimeout(async () => { await this.environmentService.setUrlsFromStorage(); + // Workaround to ignore stateService.activeAccount until URLs are set + // TODO: Remove this when implementing ticket PM-2637 + this.environmentService.initialized = true; if (!this.isPrivateMode) { await this.refreshBadge(); } diff --git a/apps/desktop/src/app/services/init.service.ts b/apps/desktop/src/app/services/init.service.ts index 8a62f3fae3..78840d1432 100644 --- a/apps/desktop/src/app/services/init.service.ts +++ b/apps/desktop/src/app/services/init.service.ts @@ -44,6 +44,9 @@ export class InitService { this.nativeMessagingService.init(); await this.stateService.init(); await this.environmentService.setUrlsFromStorage(); + // Workaround to ignore stateService.activeAccount until URLs are set + // TODO: Remove this when implementing ticket PM-2637 + this.environmentService.initialized = true; this.syncService.fullSync(true); (this.vaultTimeoutService as VaultTimeoutService).init(true); const locale = await this.stateService.getLocale(); diff --git a/apps/web/src/app/core/init.service.ts b/apps/web/src/app/core/init.service.ts index 4d4afed3fb..8e0e0d600f 100644 --- a/apps/web/src/app/core/init.service.ts +++ b/apps/web/src/app/core/init.service.ts @@ -38,14 +38,13 @@ export class InitService { init() { return async () => { - // Workaround to ignore stateService.activeAccount until process.env.URLS are set - // TODO: Remove this when implementing ticket PM-2637 - this.environmentService.initialized = false; await this.stateService.init(); const urls = process.env.URLS as Urls; urls.base ??= this.win.location.origin; await this.environmentService.setUrls(urls); + // Workaround to ignore stateService.activeAccount until process.env.URLS are set + // TODO: Remove this when implementing ticket PM-2637 this.environmentService.initialized = true; setTimeout(() => this.notificationsService.init(), 3000); diff --git a/libs/common/src/platform/services/environment.service.ts b/libs/common/src/platform/services/environment.service.ts index cd93b91e25..d8e3a761d9 100644 --- a/libs/common/src/platform/services/environment.service.ts +++ b/libs/common/src/platform/services/environment.service.ts @@ -12,7 +12,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { private readonly urlsSubject = new Subject(); urls: Observable = this.urlsSubject.asObservable(); selectedRegion?: Region; - initialized = true; + initialized = false; protected baseUrl: string; protected webVaultUrl: string; @@ -286,6 +286,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { async setRegion(region: Region) { this.selectedRegion = region; await this.stateService.setRegion(region); + if (region === Region.SelfHosted) { // If user saves a self-hosted region with empty fields, default to US if (this.isEmpty()) {