From 8e3a7239080fcf77adc49c3bae7199c782163ae0 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 5 Mar 2024 13:42:16 -0600 Subject: [PATCH] [PM-5879] Remove `backgroundWindow` reference used for determing system theme preference in Safari (#7859) * [PM-5879] Removing `backgroundWindow` reference used for determing system theme preference in Safari * [PM-5879] Removing `backgroundWindow` reference used for determing system theme preference in Safari * [PM-5879] Reworking factory logic within ThemingService factory --- apps/browser/src/background/main.background.ts | 3 --- .../src/popup/services/services.module.ts | 16 +++++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index f4505ee0d9..94e466b943 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -305,9 +305,6 @@ export default class MainBackground { stateEventRunnerService: StateEventRunnerService; ssoLoginService: SsoLoginServiceAbstraction; - // Passed to the popup for Safari to workaround issues with theming, downloading, etc. - backgroundWindow = window; - onUpdatedRan: boolean; onReplacedRan: boolean; loginToAutoFill: CipherView = null; diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 2d9d4c68da..d4c8ec57fd 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -509,13 +509,15 @@ function getBgService(service: keyof MainBackground) { stateService: StateServiceAbstraction, platformUtilsService: PlatformUtilsService, ) => { - return new ThemingService( - stateService, - // Safari doesn't properly handle the (prefers-color-scheme) media query in the popup window, it always returns light. - // In Safari we have to use the background page instead, which comes with limitations like not dynamically changing the extension theme when the system theme is changed. - platformUtilsService.isSafari() ? getBgService("backgroundWindow")() : window, - document, - ); + // Safari doesn't properly handle the (prefers-color-scheme) media query in the popup window, it always returns light. + // In Safari, we have to use the background page instead, which comes with limitations like not dynamically changing the extension theme when the system theme is changed. + let windowContext = window; + const backgroundWindow = BrowserApi.getBackgroundPage(); + if (platformUtilsService.isSafari() && backgroundWindow) { + windowContext = backgroundWindow; + } + + return new ThemingService(stateService, windowContext, document); }, deps: [StateServiceAbstraction, PlatformUtilsService], },