1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

[PM-7809] Fix memory leak in AngularThemingService for Safari extension (#9434)

* [PM-7809] Fix memory leak in AngularThemingService for Safari

* Use getSystemThemeFromWindow in createSystemThemeFromWindow
This commit is contained in:
Daniel García
2024-06-28 21:58:15 +02:00
committed by GitHub
parent 4e3fb99b9f
commit 3c7663a965
2 changed files with 19 additions and 11 deletions

View File

@@ -18,11 +18,7 @@ export class AngularThemingService implements AbstractThemingService {
static createSystemThemeFromWindow(window: Window): Observable<ThemeType> {
return merge(
// This observable should always emit at least once, so go and get the current system theme designation
of(
window.matchMedia("(prefers-color-scheme: dark)").matches
? ThemeType.Dark
: ThemeType.Light,
),
of(AngularThemingService.getSystemThemeFromWindow(window)),
// Start listening to changes
fromEvent<MediaQueryListEvent>(
window.matchMedia("(prefers-color-scheme: dark)"),
@@ -31,6 +27,17 @@ export class AngularThemingService implements AbstractThemingService {
);
}
/**
* Gets the currently active system theme based on the given window.
* @param window The window to query for the current theme.
* @returns The active system theme.
*/
static getSystemThemeFromWindow(window: Window): ThemeType {
return window.matchMedia("(prefers-color-scheme: dark)").matches
? ThemeType.Dark
: ThemeType.Light;
}
readonly theme$ = this.themeStateService.selectedTheme$.pipe(
switchMap((configuredTheme) => {
if (configuredTheme === ThemeType.System) {