From 95b8efa500d449ee4cb1c8d70edd5d4d0a2dc78c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 12 Apr 2022 10:54:41 -0700 Subject: [PATCH] Allow specifying checkFirmware override (#216) --- index.html | 22 ++++++++++++++++++++++ src/connect.ts | 1 + src/install-button.ts | 5 ++++- src/install-dialog.ts | 15 +++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 23f4d89..255b515 100644 --- a/index.html +++ b/index.html @@ -403,6 +403,28 @@ is visible in the ESP Web Tools menu when connected to a device running your firmware (as detected via Improv).

+

+ ESP Web Tools allows you to provide your own check if the device is + running the same firmware as specified in the manifest. This check can + be setting the overrides property on + <esp-web-install-button>. The value is an object + containing a + checkSameFirmwareVersion(manifest, improvInfo) function. + The manifest parameter is your manifest and + improvInfo is the information returned from Improv: + { name, firmware, version, chipFamily }. This check is only + called if the device firmware was detected via Improv. +

+
+const button = document.querySelector('esp-web-install-button');
+button.overrides = {
+  checkSameFirmwareVersion(manifest, improvInfo) {
+    const manifestFirmware = manifest.name.toLowerCase();
+    const deviceFirmware = improvInfo.firmware.toLowerCase();
+    return manifestFirmware.includes(deviceFirmware);
+  }
+};

Customizing the look and feel

diff --git a/src/connect.ts b/src/connect.ts index 0be4e19..5a9a394 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -30,6 +30,7 @@ export const connect = async (button: InstallButton) => { const el = document.createElement("ewt-install-dialog"); el.port = port; el.manifestPath = button.manifest || button.getAttribute("manifest")!; + el.overrides = button.overrides; el.addEventListener( "closed", () => { diff --git a/src/install-button.ts b/src/install-button.ts index 36cfa20..8f39784 100644 --- a/src/install-button.ts +++ b/src/install-button.ts @@ -1,4 +1,5 @@ -import { FlashState } from "./const"; +import type { FlashState } from "./const"; +import type { EwtInstallDialog } from "./install-dialog"; export class InstallButton extends HTMLElement { public static isSupported = "serial" in navigator; @@ -71,6 +72,8 @@ export class InstallButton extends HTMLElement { public renderRoot?: ShadowRoot; + public overrides: EwtInstallDialog["overrides"]; + public static preload() { import("./connect"); } diff --git a/src/install-dialog.ts b/src/install-dialog.ts index 9c894b4..70b84a8 100644 --- a/src/install-dialog.ts +++ b/src/install-dialog.ts @@ -30,13 +30,20 @@ import { dialogStyles } from "./styles"; const ERROR_ICON = "⚠️"; const OK_ICON = "🎉"; -class EwtInstallDialog extends LitElement { +export class EwtInstallDialog extends LitElement { public port!: SerialPort; public manifestPath!: string; public logger: Logger = console; + public overrides?: { + checkSameFirmwareVersion?: ( + manifest: Manifest, + deviceImprov: ImprovSerial["info"] + ) => boolean; + }; + private _manifest!: Manifest; private _info?: ImprovSerial["info"]; @@ -877,7 +884,11 @@ class EwtInstallDialog extends LitElement { * Return if the device runs same firmware as manifest. */ private get _isSameFirmware() { - return this._info?.firmware === this._manifest!.name; + return !this._info + ? false + : this.overrides?.checkSameFirmwareVersion + ? this.overrides.checkSameFirmwareVersion(this._manifest, this._info) + : this._info.firmware === this._manifest.name; } /**