forked from mystiq/hydrogen-web
Remove some logging + use wrapOrRun
This commit is contained in:
parent
683ffa9ed3
commit
a550788788
2 changed files with 32 additions and 37 deletions
|
@ -169,7 +169,7 @@ export class Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.logger.run("Platform init", async () => {
|
await this.logger.run("Platform init", async (log) => {
|
||||||
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,7 +183,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(), log);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,9 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import type {ILogItem} from "../../logging/types.js";
|
||||||
import type {Platform} from "./Platform.js";
|
import type {Platform} from "./Platform.js";
|
||||||
|
|
||||||
export enum COLOR_SCHEME_PREFERENCE { DARK, LIGHT, }
|
|
||||||
|
|
||||||
export class ThemeLoader {
|
export class ThemeLoader {
|
||||||
private _platform: Platform;
|
private _platform: Platform;
|
||||||
private _themeMapping: Record<string, string> = {};
|
private _themeMapping: Record<string, string> = {};
|
||||||
|
@ -27,7 +26,6 @@ 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, {
|
||||||
|
@ -43,11 +41,10 @@ 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, log?: ILogItem) {
|
||||||
this._platform.logger.run("ThemeLoader.setTheme", () => {
|
this._platform.logger.wrapOrRun(log, "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}"!`);
|
||||||
|
@ -62,7 +59,6 @@ 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) {
|
||||||
|
@ -75,6 +71,5 @@ export class ThemeLoader {
|
||||||
return this._platform.config["defaultTheme"].light;
|
return this._platform.config["defaultTheme"].light;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue