Browse Source

feat: Add dynamic theme-color meta

pull/3129/head
Miguel Coxo 2 years ago
parent
commit
fb11b08c34
  1. 8
      apps/client/src/app/app.component.ts

8
apps/client/src/app/app.component.ts

@ -193,10 +193,12 @@ export class AppComponent implements OnDestroy, OnInit {
: window.matchMedia('(prefers-color-scheme: dark)').matches;
this.toggleThemeStyleClass(isDarkTheme);
this.toggleMetaThemeColor(isDarkTheme);
window.matchMedia('(prefers-color-scheme: dark)').addListener((event) => {
if (!this.user?.settings.colorScheme) {
this.toggleThemeStyleClass(event.matches);
this.toggleMetaThemeColor(event.matches);
}
});
}
@ -208,4 +210,10 @@ export class AppComponent implements OnDestroy, OnInit {
this.document.body.classList.remove('is-dark-theme');
}
}
private toggleMetaThemeColor(isDarkTheme: boolean) {
const color = isDarkTheme ? 'rgb(25, 25, 25)' : 'rgb(255, 255, 255)';
const metaTag = this.document.querySelector('meta[name="theme-color"]');
metaTag.setAttribute('content', color);
}
}

Loading…
Cancel
Save