diff --git a/ts/domtools.classes.thememanager.ts b/ts/domtools.classes.thememanager.ts index 3c48ab4..c572b7c 100644 --- a/ts/domtools.classes.thememanager.ts +++ b/ts/domtools.classes.thememanager.ts @@ -6,12 +6,22 @@ export class ThemeManager { public domtoolsRef: DomTools; public goBrightBoolean = false; + public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)'); constructor(domtoolsRefArg: DomTools) { this.domtoolsRef = domtoolsRefArg; + + // lets take care of elements being added that need to know of the current theme this.domtoolsRef.elementInstrumenter.connectedElements.eventSubject.subscribe(async eventData => { await this.setThemeStatusForElement(eventData.payload, this.goBrightBoolean); }); + + // lets care + this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches; + this.preferredColorSchemeMediaMatch.addEventListener('change', eventArg => { + this.goBrightBoolean = eventArg.matches; + this.updateAllConnectedElements(); + }); } private async setThemeStatusForElement (elementArg: LitElement, goBrightBool: boolean) {