mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
[EC-157] [BEEEP] Remove factory providers in Angular DI (#2516)
* Use initService * Use InjectionTokens * Update to use new locked and logout callbacks
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 6bcadc4f40...e40e7de808
@@ -267,21 +267,21 @@ export default class MainBackground {
|
|||||||
this.cryptoFunctionService
|
this.cryptoFunctionService
|
||||||
);
|
);
|
||||||
|
|
||||||
const vaultTimeoutServiceCallbacks = {
|
const lockedCallback = async (userId?: string) => {
|
||||||
locked: async (userId?: string) => {
|
if (this.notificationsService != null) {
|
||||||
if (this.notificationsService != null) {
|
this.notificationsService.updateConnection(false);
|
||||||
this.notificationsService.updateConnection(false);
|
}
|
||||||
}
|
await this.setIcon();
|
||||||
await this.setIcon();
|
await this.refreshBadgeAndMenu(true);
|
||||||
await this.refreshBadgeAndMenu(true);
|
if (this.systemService != null) {
|
||||||
if (this.systemService != null) {
|
await this.systemService.clearPendingClipboard();
|
||||||
await this.systemService.clearPendingClipboard();
|
await this.reloadProcess();
|
||||||
await this.reloadProcess();
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
logout: async (userId?: string) => await this.logout(false, userId),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const logoutCallback = async (expired: boolean, userId?: string) =>
|
||||||
|
await this.logout(expired, userId);
|
||||||
|
|
||||||
this.vaultTimeoutService = new VaultTimeoutService(
|
this.vaultTimeoutService = new VaultTimeoutService(
|
||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.folderService,
|
this.folderService,
|
||||||
@@ -294,8 +294,8 @@ export default class MainBackground {
|
|||||||
this.policyService,
|
this.policyService,
|
||||||
this.keyConnectorService,
|
this.keyConnectorService,
|
||||||
this.stateService,
|
this.stateService,
|
||||||
vaultTimeoutServiceCallbacks.locked,
|
lockedCallback,
|
||||||
vaultTimeoutServiceCallbacks.logout
|
logoutCallback
|
||||||
);
|
);
|
||||||
this.providerService = new ProviderService(this.stateService);
|
this.providerService = new ProviderService(this.stateService);
|
||||||
this.syncService = new SyncService(
|
this.syncService = new SyncService(
|
||||||
@@ -313,7 +313,7 @@ export default class MainBackground {
|
|||||||
this.stateService,
|
this.stateService,
|
||||||
this.organizationService,
|
this.organizationService,
|
||||||
this.providerService,
|
this.providerService,
|
||||||
async (expired: boolean) => await this.logout(expired)
|
logoutCallback
|
||||||
);
|
);
|
||||||
this.eventService = new EventService(
|
this.eventService = new EventService(
|
||||||
this.apiService,
|
this.apiService,
|
||||||
@@ -354,7 +354,7 @@ export default class MainBackground {
|
|||||||
this.apiService,
|
this.apiService,
|
||||||
this.vaultTimeoutService,
|
this.vaultTimeoutService,
|
||||||
this.environmentService,
|
this.environmentService,
|
||||||
() => this.logout(true),
|
logoutCallback,
|
||||||
this.logService,
|
this.logService,
|
||||||
this.stateService
|
this.stateService
|
||||||
);
|
);
|
||||||
|
|||||||
62
src/popup/services/init.service.ts
Normal file
62
src/popup/services/init.service.ts
Normal file
@@ -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");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { APP_INITIALIZER, LOCALE_ID, NgModule } from "@angular/core";
|
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 { LockGuardService as BaseLockGuardService } from "jslib-angular/services/lock-guard.service";
|
||||||
import { UnauthGuardService as BaseUnauthGuardService } from "jslib-angular/services/unauth-guard.service";
|
import { UnauthGuardService as BaseUnauthGuardService } from "jslib-angular/services/unauth-guard.service";
|
||||||
import { ApiService } from "jslib-common/abstractions/api.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 { UserVerificationService } from "jslib-common/abstractions/userVerification.service";
|
||||||
import { UsernameGenerationService } from "jslib-common/abstractions/usernameGeneration.service";
|
import { UsernameGenerationService } from "jslib-common/abstractions/usernameGeneration.service";
|
||||||
import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.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 { AuthService } from "jslib-common/services/auth.service";
|
||||||
import { ConsoleLogService } from "jslib-common/services/consoleLog.service";
|
import { ConsoleLogService } from "jslib-common/services/consoleLog.service";
|
||||||
import { SearchService } from "jslib-common/services/search.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 BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service";
|
||||||
|
|
||||||
import { DebounceNavigationService } from "./debounceNavigationService";
|
import { DebounceNavigationService } from "./debounceNavigationService";
|
||||||
|
import { InitService } from "./init.service";
|
||||||
import { LockGuardService } from "./lock-guard.service";
|
import { LockGuardService } from "./lock-guard.service";
|
||||||
import { PasswordRepromptService } from "./password-reprompt.service";
|
import { PasswordRepromptService } from "./password-reprompt.service";
|
||||||
import { PopupSearchService } from "./popup-search.service";
|
import { PopupSearchService } from "./popup-search.service";
|
||||||
@@ -75,73 +75,12 @@ function getBgService<T>(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({
|
@NgModule({
|
||||||
imports: [JslibServicesModule],
|
imports: [JslibServicesModule],
|
||||||
declarations: [],
|
declarations: [],
|
||||||
providers: [
|
providers: [
|
||||||
|
InitService,
|
||||||
|
DebounceNavigationService,
|
||||||
{
|
{
|
||||||
provide: LOCALE_ID,
|
provide: LOCALE_ID,
|
||||||
useFactory: () => getBgService<I18nService>("i18nService")().translationLocale,
|
useFactory: () => getBgService<I18nService>("i18nService")().translationLocale,
|
||||||
@@ -149,19 +88,12 @@ export function initFactory(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
useFactory: initFactory,
|
useFactory: (initService: InitService) => initService.init(),
|
||||||
deps: [
|
deps: [InitService],
|
||||||
PlatformUtilsService,
|
|
||||||
I18nService,
|
|
||||||
PopupUtilsService,
|
|
||||||
StateServiceAbstraction,
|
|
||||||
LogServiceAbstraction,
|
|
||||||
],
|
|
||||||
multi: true,
|
multi: true,
|
||||||
},
|
},
|
||||||
{ provide: BaseLockGuardService, useClass: LockGuardService },
|
{ provide: BaseLockGuardService, useClass: LockGuardService },
|
||||||
{ provide: BaseUnauthGuardService, useClass: UnauthGuardService },
|
{ provide: BaseUnauthGuardService, useClass: UnauthGuardService },
|
||||||
DebounceNavigationService,
|
|
||||||
{ provide: PopupUtilsService, useFactory: () => new PopupUtilsService(isPrivateMode) },
|
{ provide: PopupUtilsService, useFactory: () => new PopupUtilsService(isPrivateMode) },
|
||||||
{
|
{
|
||||||
provide: MessagingService,
|
provide: MessagingService,
|
||||||
@@ -176,11 +108,6 @@ export function initFactory(
|
|||||||
useFactory: getBgService<TwoFactorService>("twoFactorService"),
|
useFactory: getBgService<TwoFactorService>("twoFactorService"),
|
||||||
deps: [],
|
deps: [],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
provide: TwoFactorService,
|
|
||||||
useFactory: getBgService<TwoFactorService>("twoFactorService"),
|
|
||||||
deps: [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
provide: AuthServiceAbstraction,
|
provide: AuthServiceAbstraction,
|
||||||
useFactory: getBgService<AuthService>("authService"),
|
useFactory: getBgService<AuthService>("authService"),
|
||||||
@@ -303,7 +230,7 @@ export function initFactory(
|
|||||||
deps: [],
|
deps: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: "SECURE_STORAGE",
|
provide: SECURE_STORAGE,
|
||||||
useFactory: getBgService<StorageServiceAbstraction>("secureStorageService"),
|
useFactory: getBgService<StorageServiceAbstraction>("secureStorageService"),
|
||||||
deps: [],
|
deps: [],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user