diff --git a/src/components/ewt-console.ts b/src/components/ewt-console.ts index 9942a08..3136204 100644 --- a/src/components/ewt-console.ts +++ b/src/components/ewt-console.ts @@ -11,6 +11,10 @@ export class EwtConsole extends HTMLElement { private _console?: ColoredConsole; private _cancelConnection?: () => Promise; + public logs(): string { + return this._console?.logs() || ""; + } + public connectedCallback() { if (this._console) { return; diff --git a/src/install-dialog.ts b/src/install-dialog.ts index 279ae27..e63656d 100644 --- a/src/install-dialog.ts +++ b/src/install-dialog.ts @@ -19,6 +19,7 @@ import { PortNotReady, } from "improv-wifi-serial-sdk/dist/const"; import { flash } from "./flash"; +import { textDownload } from "./util/file-download"; import { fireEvent } from "./util/fire-event"; import { sleep } from "./util/sleep"; import { downloadManifest } from "./util/manifest"; @@ -587,6 +588,18 @@ class EwtInstallDialog extends LitElement { this._initialize(); }} > + { + textDownload( + this.shadowRoot!.querySelector("ewt-console")!.logs(), + `esp-web-tools-logs.txt` + ); + + this.shadowRoot!.querySelector("ewt-console")!.reset(); + }} + > { + const a = document.createElement("a"); + a.target = "_blank"; + a.href = href; + a.download = filename; + + document.body.appendChild(a); + a.dispatchEvent(new MouseEvent("click")); + document.body.removeChild(a); +}; + +export const textDownload = (text: string, filename = ""): void => { + const blob = new Blob([text], { type: "text/plain" }); + const url = URL.createObjectURL(blob); + fileDownload(url, filename); + setTimeout(() => URL.revokeObjectURL(url), 0); +};