fix(core): update
This commit is contained in:
@ -8,34 +8,23 @@ export class ThemeManager {
|
||||
public goBrightBoolean = false;
|
||||
public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)');
|
||||
|
||||
public themeObservable = new plugins.smartrx.rxjs.ReplaySubject<boolean>(1);
|
||||
|
||||
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) {
|
||||
const goBright = (elementArg as any).goBright;
|
||||
if (typeof goBright === 'boolean') {
|
||||
(elementArg as any).goBright = goBrightBool;
|
||||
}
|
||||
this.updateAllConnectedElements();
|
||||
}
|
||||
|
||||
private async updateAllConnectedElements() {
|
||||
document.body.style.background = this.goBrightBoolean ? '#fff' : '#000';
|
||||
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
|
||||
await this.setThemeStatusForElement(elementArg, this.goBrightBoolean);
|
||||
});
|
||||
this.themeObservable.next(this.goBrightBoolean);
|
||||
}
|
||||
|
||||
public goBright() {
|
||||
|
Reference in New Issue
Block a user