diff --git a/jslib b/jslib index 6bcadc4f40..e40e7de808 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 6bcadc4f408db2c150753f53a07d6f8888b6e9ff +Subproject commit e40e7de8083ecfe220ef7f94f7447d560f822272 diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 3cdad7b080..4910a53a71 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -267,21 +267,21 @@ export default class MainBackground { this.cryptoFunctionService ); - const vaultTimeoutServiceCallbacks = { - locked: async (userId?: string) => { - if (this.notificationsService != null) { - this.notificationsService.updateConnection(false); - } - await this.setIcon(); - await this.refreshBadgeAndMenu(true); - if (this.systemService != null) { - await this.systemService.clearPendingClipboard(); - await this.reloadProcess(); - } - }, - logout: async (userId?: string) => await this.logout(false, userId), + const lockedCallback = async (userId?: string) => { + if (this.notificationsService != null) { + this.notificationsService.updateConnection(false); + } + await this.setIcon(); + await this.refreshBadgeAndMenu(true); + if (this.systemService != null) { + await this.systemService.clearPendingClipboard(); + await this.reloadProcess(); + } }; + const logoutCallback = async (expired: boolean, userId?: string) => + await this.logout(expired, userId); + this.vaultTimeoutService = new VaultTimeoutService( this.cipherService, this.folderService, @@ -294,8 +294,8 @@ export default class MainBackground { this.policyService, this.keyConnectorService, this.stateService, - vaultTimeoutServiceCallbacks.locked, - vaultTimeoutServiceCallbacks.logout + lockedCallback, + logoutCallback ); this.providerService = new ProviderService(this.stateService); this.syncService = new SyncService( @@ -313,7 +313,7 @@ export default class MainBackground { this.stateService, this.organizationService, this.providerService, - async (expired: boolean) => await this.logout(expired) + logoutCallback ); this.eventService = new EventService( this.apiService, @@ -354,7 +354,7 @@ export default class MainBackground { this.apiService, this.vaultTimeoutService, this.environmentService, - () => this.logout(true), + logoutCallback, this.logService, this.stateService ); diff --git a/src/popup/services/init.service.ts b/src/popup/services/init.service.ts new file mode 100644 index 0000000000..e128e9c090 --- /dev/null +++ b/src/popup/services/init.service.ts @@ -0,0 +1,62 @@ +import { Injectable } from "@angular/core"; + +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { LogService as LogServiceAbstraction } from "jslib-common/abstractions/log.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; +import { ThemeType } from "jslib-common/enums/themeType"; + +import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service"; + +import { PopupUtilsService } from "./popup-utils.service"; + +@Injectable() +export class InitService { + constructor( + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private popupUtilsService: PopupUtilsService, + private stateService: StateServiceAbstraction, + private logService: LogServiceAbstraction + ) {} + + init() { + return async () => { + await this.stateService.init(); + + if (!this.popupUtilsService.inPopup(window)) { + window.document.body.classList.add("body-full"); + } else if (window.screen.availHeight < 600) { + window.document.body.classList.add("body-xs"); + } else if (window.screen.availHeight <= 800) { + window.document.body.classList.add("body-sm"); + } + + const htmlEl = window.document.documentElement; + const theme = await this.platformUtilsService.getEffectiveTheme(); + htmlEl.classList.add("theme_" + theme); + this.platformUtilsService.onDefaultSystemThemeChange(async (sysTheme) => { + const bwTheme = await this.stateService.getTheme(); + if (bwTheme == null || bwTheme === ThemeType.System) { + htmlEl.classList.remove("theme_" + ThemeType.Light, "theme_" + ThemeType.Dark); + htmlEl.classList.add("theme_" + sysTheme); + } + }); + htmlEl.classList.add("locale_" + this.i18nService.translationLocale); + + // Workaround for slow performance on external monitors on Chrome + MacOS + // See: https://bugs.chromium.org/p/chromium/issues/detail?id=971701#c64 + if ( + this.platformUtilsService.isChrome() && + navigator.platform.indexOf("Mac") > -1 && + this.popupUtilsService.inPopup(window) && + (window.screenLeft < 0 || + window.screenTop < 0 || + window.screenLeft > window.screen.width || + window.screenTop > window.screen.height) + ) { + htmlEl.classList.add("force_redraw"); + this.logService.info("Force redraw is on"); + } + }; + } +} diff --git a/src/popup/services/services.module.ts b/src/popup/services/services.module.ts index 8229cf6d3f..62591efd7c 100644 --- a/src/popup/services/services.module.ts +++ b/src/popup/services/services.module.ts @@ -1,6 +1,6 @@ import { APP_INITIALIZER, LOCALE_ID, NgModule } from "@angular/core"; -import { JslibServicesModule } from "jslib-angular/services/jslib-services.module"; +import { JslibServicesModule, SECURE_STORAGE } from "jslib-angular/services/jslib-services.module"; import { LockGuardService as BaseLockGuardService } from "jslib-angular/services/lock-guard.service"; import { UnauthGuardService as BaseUnauthGuardService } from "jslib-angular/services/unauth-guard.service"; import { ApiService } from "jslib-common/abstractions/api.service"; @@ -39,7 +39,6 @@ import { TwoFactorService } from "jslib-common/abstractions/twoFactor.service"; import { UserVerificationService } from "jslib-common/abstractions/userVerification.service"; import { UsernameGenerationService } from "jslib-common/abstractions/usernameGeneration.service"; import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.service"; -import { ThemeType } from "jslib-common/enums/themeType"; import { AuthService } from "jslib-common/services/auth.service"; import { ConsoleLogService } from "jslib-common/services/consoleLog.service"; import { SearchService } from "jslib-common/services/search.service"; @@ -52,6 +51,7 @@ import BrowserMessagingService from "../../services/browserMessaging.service"; import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service"; import { DebounceNavigationService } from "./debounceNavigationService"; +import { InitService } from "./init.service"; import { LockGuardService } from "./lock-guard.service"; import { PasswordRepromptService } from "./password-reprompt.service"; import { PopupSearchService } from "./popup-search.service"; @@ -75,73 +75,12 @@ function getBgService(service: keyof MainBackground) { }; } -export function initFactory( - platformUtilsService: PlatformUtilsService, - i18nService: I18nService, - popupUtilsService: PopupUtilsService, - stateService: StateServiceAbstraction, - logService: LogServiceAbstraction -): () => void { - return async () => { - await stateService.init(); - - if (!popupUtilsService.inPopup(window)) { - window.document.body.classList.add("body-full"); - } else if (window.screen.availHeight < 600) { - window.document.body.classList.add("body-xs"); - } else if (window.screen.availHeight <= 800) { - window.document.body.classList.add("body-sm"); - } - - const htmlEl = window.document.documentElement; - const theme = await platformUtilsService.getEffectiveTheme(); - htmlEl.classList.add("theme_" + theme); - platformUtilsService.onDefaultSystemThemeChange(async (sysTheme) => { - const bwTheme = await stateService.getTheme(); - if (bwTheme == null || bwTheme === ThemeType.System) { - htmlEl.classList.remove("theme_" + ThemeType.Light, "theme_" + ThemeType.Dark); - htmlEl.classList.add("theme_" + sysTheme); - } - }); - htmlEl.classList.add("locale_" + i18nService.translationLocale); - - // Workaround for slow performance on external monitors on Chrome + MacOS - // See: https://bugs.chromium.org/p/chromium/issues/detail?id=971701#c64 - if ( - platformUtilsService.isChrome() && - navigator.platform.indexOf("Mac") > -1 && - popupUtilsService.inPopup(window) && - (window.screenLeft < 0 || - window.screenTop < 0 || - window.screenLeft > window.screen.width || - window.screenTop > window.screen.height) - ) { - htmlEl.classList.add("force_redraw"); - logService.info("Force redraw is on"); - } - htmlEl.classList.add("locale_" + i18nService.translationLocale); - - // Workaround for slow performance on external monitors on Chrome + MacOS - // See: https://bugs.chromium.org/p/chromium/issues/detail?id=971701#c64 - if ( - platformUtilsService.isChrome() && - navigator.platform.indexOf("Mac") > -1 && - popupUtilsService.inPopup(window) && - (window.screenLeft < 0 || - window.screenTop < 0 || - window.screenLeft > window.screen.width || - window.screenTop > window.screen.height) - ) { - htmlEl.classList.add("force_redraw"); - logService.info("Force redraw is on"); - } - }; -} - @NgModule({ imports: [JslibServicesModule], declarations: [], providers: [ + InitService, + DebounceNavigationService, { provide: LOCALE_ID, useFactory: () => getBgService("i18nService")().translationLocale, @@ -149,19 +88,12 @@ export function initFactory( }, { provide: APP_INITIALIZER, - useFactory: initFactory, - deps: [ - PlatformUtilsService, - I18nService, - PopupUtilsService, - StateServiceAbstraction, - LogServiceAbstraction, - ], + useFactory: (initService: InitService) => initService.init(), + deps: [InitService], multi: true, }, { provide: BaseLockGuardService, useClass: LockGuardService }, { provide: BaseUnauthGuardService, useClass: UnauthGuardService }, - DebounceNavigationService, { provide: PopupUtilsService, useFactory: () => new PopupUtilsService(isPrivateMode) }, { provide: MessagingService, @@ -176,11 +108,6 @@ export function initFactory( useFactory: getBgService("twoFactorService"), deps: [], }, - { - provide: TwoFactorService, - useFactory: getBgService("twoFactorService"), - deps: [], - }, { provide: AuthServiceAbstraction, useFactory: getBgService("authService"), @@ -303,7 +230,7 @@ export function initFactory( deps: [], }, { - provide: "SECURE_STORAGE", + provide: SECURE_STORAGE, useFactory: getBgService("secureStorageService"), deps: [], },