Add logging

This commit is contained in:
RMidhunSuresh 2022-05-18 16:09:09 +05:30
parent 7426d17e33
commit 7952a34d64
2 changed files with 54 additions and 46 deletions

View File

@ -169,6 +169,7 @@ export class Platform {
} }
async init() { async init() {
await this.logger.run("Platform init", async () => {
if (!this._config) { if (!this._config) {
if (!this._configURL) { if (!this._configURL) {
throw new Error("Neither config nor configURL was provided!"); throw new Error("Neither config nor configURL was provided!");
@ -183,6 +184,7 @@ export class Platform {
const manifests = this.config["themeManifests"]; const manifests = this.config["themeManifests"];
await this._themeLoader?.init(manifests); await this._themeLoader?.init(manifests);
this._themeLoader?.setTheme(await this._themeLoader.getActiveTheme()); this._themeLoader?.setTheme(await this._themeLoader.getActiveTheme());
});
} }
_createLogger(isDevelopment) { _createLogger(isDevelopment) {

View File

@ -27,6 +27,7 @@ export class ThemeLoader {
} }
async init(manifestLocations: string[]): Promise<void> { async init(manifestLocations: string[]): Promise<void> {
await this._platform.logger.run("ThemeLoader.init", async () => {
for (const manifestLocation of manifestLocations) { for (const manifestLocation of manifestLocations) {
const { body } = await this._platform const { body } = await this._platform
.request(manifestLocation, { .request(manifestLocation, {
@ -42,15 +43,18 @@ export class ThemeLoader {
*/ */
Object.assign(this._themeMapping, body["source"]["built-assets"]); Object.assign(this._themeMapping, body["source"]["built-assets"]);
} }
});
} }
setTheme(themeName: string) { setTheme(themeName: string) {
this._platform.logger.run("ThemeLoader.setTheme", () => {
const themeLocation = this._themeMapping[themeName]; const themeLocation = this._themeMapping[themeName];
if (!themeLocation) { if (!themeLocation) {
throw new Error( `Cannot find theme location for theme "${themeName}"!`); throw new Error( `Cannot find theme location for theme "${themeName}"!`);
} }
this._platform.replaceStylesheet(themeLocation); this._platform.replaceStylesheet(themeLocation);
this._platform.settingsStorage.setString("theme", themeName); this._platform.settingsStorage.setString("theme", themeName);
});
} }
get themes(): string[] { get themes(): string[] {
@ -58,6 +62,7 @@ export class ThemeLoader {
} }
async getActiveTheme(): Promise<string|undefined> { async getActiveTheme(): Promise<string|undefined> {
return await this._platform.logger.run("ThemeLoader.getActiveTheme", async () => {
// check if theme is set via settings // check if theme is set via settings
let theme = await this._platform.settingsStorage.getString("theme"); let theme = await this._platform.settingsStorage.getString("theme");
if (theme) { if (theme) {
@ -70,5 +75,6 @@ export class ThemeLoader {
return this._platform.config["defaultTheme"].light; return this._platform.config["defaultTheme"].light;
} }
return undefined; return undefined;
});
} }
} }