mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Add logging
This commit is contained in:
parent
ce5db47708
commit
9e2d355573
@ -19,6 +19,7 @@ import {ColorSchemePreference} from "./ThemeLoader";
|
|||||||
import {IconColorizer} from "./IconColorizer";
|
import {IconColorizer} from "./IconColorizer";
|
||||||
import {DerivedVariables} from "./DerivedVariables";
|
import {DerivedVariables} from "./DerivedVariables";
|
||||||
import {ThemeManifest} from "../types/theme";
|
import {ThemeManifest} from "../types/theme";
|
||||||
|
import {ILogItem} from "../../logging/types";
|
||||||
|
|
||||||
export class ThemeBuilder {
|
export class ThemeBuilder {
|
||||||
private _idToManifest: Map<string, {manifest: ThemeManifest, location: string}>;
|
private _idToManifest: Map<string, {manifest: ThemeManifest, location: string}>;
|
||||||
@ -33,9 +34,10 @@ export class ThemeBuilder {
|
|||||||
this._platform = platform;
|
this._platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
async populateDerivedTheme(manifest: ThemeManifest) {
|
async populateDerivedTheme(manifest: ThemeManifest, log: ILogItem) {
|
||||||
|
await log.wrap("ThemeBuilder.populateThemeMap", async (l) => {
|
||||||
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
|
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
|
||||||
const { cssLocation, derivedVariables, icons } = this._getsourceData(baseManifest, location);
|
const {cssLocation, derivedVariables, icons} = this._getSourceData(baseManifest, location, log);
|
||||||
const themeName = manifest.name;
|
const themeName = manifest.name;
|
||||||
if (!themeName) {
|
if (!themeName) {
|
||||||
throw new Error(`Theme name not found in manifest!`);
|
throw new Error(`Theme name not found in manifest!`);
|
||||||
@ -70,9 +72,11 @@ export class ThemeBuilder {
|
|||||||
const variant = defaultDarkVariant.id ? defaultDarkVariant : defaultLightVariant;
|
const variant = defaultDarkVariant.id ? defaultDarkVariant : defaultLightVariant;
|
||||||
this._themeMapping[`${themeName} ${variant.variantName}`] = { id: variant.id, cssLocation: variant.cssLocation };
|
this._themeMapping[`${themeName} ${variant.variantName}`] = { id: variant.id, cssLocation: variant.cssLocation };
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getsourceData(manifest: ThemeManifest, location: string) {
|
private _getSourceData(manifest: ThemeManifest, location: string, log:ILogItem) {
|
||||||
|
return log.wrap("getSourceData", () => {
|
||||||
const runtimeCSSLocation = manifest.source?.["runtime-asset"];
|
const runtimeCSSLocation = manifest.source?.["runtime-asset"];
|
||||||
if (!runtimeCSSLocation) {
|
if (!runtimeCSSLocation) {
|
||||||
throw new Error(`Run-time asset not found in source section for theme at ${location}`);
|
throw new Error(`Run-time asset not found in source section for theme at ${location}`);
|
||||||
@ -87,6 +91,7 @@ export class ThemeBuilder {
|
|||||||
throw new Error(`Icon mapping not found in source section for theme at ${location}`);
|
throw new Error(`Icon mapping not found in source section for theme at ${location}`);
|
||||||
}
|
}
|
||||||
return { cssLocation, derivedVariables, icons };
|
return { cssLocation, derivedVariables, icons };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get themeMapping() {
|
get themeMapping() {
|
||||||
|
@ -64,7 +64,7 @@ export class ThemeLoader {
|
|||||||
const { body } = results[i];
|
const { body } = results[i];
|
||||||
try {
|
try {
|
||||||
if (body.extends) {
|
if (body.extends) {
|
||||||
await this._themeBuilder.populateDerivedTheme(body);
|
await this._themeBuilder.populateDerivedTheme(body, log);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._populateThemeMap(body, manifestLocations[i], log);
|
this._populateThemeMap(body, manifestLocations[i], log);
|
||||||
@ -183,6 +183,7 @@ export class ThemeLoader {
|
|||||||
}
|
}
|
||||||
this._platform.replaceStylesheet(cssLocation);
|
this._platform.replaceStylesheet(cssLocation);
|
||||||
if (variables) {
|
if (variables) {
|
||||||
|
log?.log({l: "Derived Theme", variables});
|
||||||
this._themeBuilder.injectCSSVariables(variables);
|
this._themeBuilder.injectCSSVariables(variables);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user