Remove some logging + use wrapOrRun

This commit is contained in:
RMidhunSuresh 2022-05-18 18:56:28 +05:30
parent 683ffa9ed3
commit a550788788
2 changed files with 32 additions and 37 deletions

View file

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

View file

@ -14,10 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import type {ILogItem} from "../../logging/types.js";
import type {Platform} from "./Platform.js";
export enum COLOR_SCHEME_PREFERENCE { DARK, LIGHT, }
export class ThemeLoader {
private _platform: Platform;
private _themeMapping: Record<string, string> = {};
@ -27,7 +26,6 @@ export class ThemeLoader {
}
async init(manifestLocations: string[]): Promise<void> {
await this._platform.logger.run("ThemeLoader.init", async () => {
for (const manifestLocation of manifestLocations) {
const { body } = await this._platform
.request(manifestLocation, {
@ -43,11 +41,10 @@ export class ThemeLoader {
*/
Object.assign(this._themeMapping, body["source"]["built-assets"]);
}
});
}
setTheme(themeName: string) {
this._platform.logger.run("ThemeLoader.setTheme", () => {
setTheme(themeName: string, log?: ILogItem) {
this._platform.logger.wrapOrRun(log, "setTheme", () => {
const themeLocation = this._themeMapping[themeName];
if (!themeLocation) {
throw new Error( `Cannot find theme location for theme "${themeName}"!`);
@ -62,7 +59,6 @@ export class ThemeLoader {
}
async getActiveTheme(): Promise<string|undefined> {
return await this._platform.logger.run("ThemeLoader.getActiveTheme", async () => {
// check if theme is set via settings
let theme = await this._platform.settingsStorage.getString("theme");
if (theme) {
@ -75,6 +71,5 @@ export class ThemeLoader {
return this._platform.config["defaultTheme"].light;
}
return undefined;
});
}
}