From a83239e0d90b82e078eb23fd13a8a929426beff0 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 25 Nov 2020 15:42:55 +0000 Subject: [PATCH] fix(core): update --- ts/domtools.classes.thememanager.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) {