mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +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:
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");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user