Skip to content

Commit

Permalink
Add configuration option to disable the log UI. (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 committed Jun 21, 2023
1 parent e898f92 commit 67c48ee
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions v2/esp-app.ts
Expand Up @@ -13,6 +13,7 @@ window.source = new EventSource(getBasePath() + "/events");

interface Config {
ota: boolean;
log: boolean;
title: string;
comment: string;
}
Expand All @@ -25,7 +26,7 @@ export default class EspApp extends LitElement {
beat!: HTMLSpanElement;

version: String = import.meta.env.PACKAGE_VERSION;
config: Config = { ota: false, title: "", comment: "" };
config: Config = { ota: false, log: true, title: "", comment: "" };

darkQuery: MediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");

Expand All @@ -37,6 +38,15 @@ export default class EspApp extends LitElement {

constructor() {
super();
const conf = document.querySelector('script#config');
if ( conf ) this.setConfig(JSON.parse(conf.innerText));
}

setConfig(config: any) {
this.config = config;

document.title = config.title;
document.documentElement.lang = config.lang;
}

firstUpdated(changedProperties: PropertyValues) {
Expand All @@ -54,11 +64,7 @@ export default class EspApp extends LitElement {
const messageEvent = e as MessageEvent;
const d: String = messageEvent.data;
if (d.length) {
const config = JSON.parse(messageEvent.data);
this.config = config;

document.title = config.title;
document.documentElement.lang = config.lang;
this.setConfig(JSON.parse(messageEvent.data));
}
this.ping = messageEvent.lastEventId;
});
Expand Down Expand Up @@ -104,6 +110,12 @@ export default class EspApp extends LitElement {
: nothing;
}

renderLog() {
return this.config.log
? html`<section class="col"><esp-log rows="50"></esp-log></section>`
: nothing;
}

render() {
return html`
<h1>
Expand Down Expand Up @@ -134,9 +146,7 @@ export default class EspApp extends LitElement {
</h2>
${this.ota()}
</section>
<section class="col">
<esp-log rows="50"></esp-log>
</section>
${this.renderLog()}
</main>
`;
}
Expand Down

0 comments on commit 67c48ee

Please sign in to comment.