Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Optimize colorModeContrastPreferences initialization

Kabiru Mwenja5ee830fec44b
diff --git a/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts b/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
index 10234e844cd..50b459a824c 100644
--- a/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
+++ b/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
@@ -52,6 +52,8 @@ export default class AutoThemeSwitcher extends Controller {
declare readonly desktopLightHighContrastLogoClass:string;
declare readonly mobileWhiteLogoClass:string;
+ private colorModeContrastPreferences:Record<OpColorMode, boolean>;
+
connect() {
if (this.themeValue === 'sync_with_os') {
this.syncWithOS();
@@ -61,6 +63,11 @@ export default class AutoThemeSwitcher extends Controller {
}
syncWithOS():void {
+ this.colorModeContrastPreferences = {
+ light: this.enableAutoLightThemeContrastValue,
+ dark: this.enableAutoDarkThemeContrastValue,
+ };
+
useMatchMedia(this, {
mediaQueries: {
lightMode: '(prefers-color-scheme: light)',
@@ -99,10 +106,4 @@ export default class AutoThemeSwitcher extends Controller {
this.mobileLogoTarget.classList.toggle(this.mobileWhiteLogoClass, !isLightHighContrast);
}
- private get colorModeContrastPreferences():Record<OpColorMode, boolean> {
- return {
- light: this.enableAutoLightThemeContrastValue,
- dark: this.enableAutoDarkThemeContrastValue,
- };
- }
}