Allow specifying checkFirmware override (#216)

This commit is contained in:
Paulus Schoutsen 2022-04-12 10:54:41 -07:00 committed by GitHub
parent 22c0a1a1cb
commit 95b8efa500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 3 deletions

View File

@ -403,6 +403,28 @@
is visible in the ESP Web Tools menu when connected to a device running is visible in the ESP Web Tools menu when connected to a device running
your firmware (as detected via Improv). your firmware (as detected via Improv).
</p> </p>
<p>
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 <code>overrides</code> property on
<code>&lt;esp-web-install-button&gt;</code>. The value is an object
containing a
<code>checkSameFirmwareVersion(manifest, improvInfo)</code> function.
The <code>manifest</code> parameter is your manifest and
<code>improvInfo</code> is the information returned from Improv:
<code>{ name, firmware, version, chipFamily }</code>. This check is only
called if the device firmware was detected via Improv.
</p>
<pre>
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);
}
};</pre
>
<h3 id="customize">Customizing the look and feel</h3> <h3 id="customize">Customizing the look and feel</h3>
<p> <p>

View File

@ -30,6 +30,7 @@ export const connect = async (button: InstallButton) => {
const el = document.createElement("ewt-install-dialog"); const el = document.createElement("ewt-install-dialog");
el.port = port; el.port = port;
el.manifestPath = button.manifest || button.getAttribute("manifest")!; el.manifestPath = button.manifest || button.getAttribute("manifest")!;
el.overrides = button.overrides;
el.addEventListener( el.addEventListener(
"closed", "closed",
() => { () => {

View File

@ -1,4 +1,5 @@
import { FlashState } from "./const"; import type { FlashState } from "./const";
import type { EwtInstallDialog } from "./install-dialog";
export class InstallButton extends HTMLElement { export class InstallButton extends HTMLElement {
public static isSupported = "serial" in navigator; public static isSupported = "serial" in navigator;
@ -71,6 +72,8 @@ export class InstallButton extends HTMLElement {
public renderRoot?: ShadowRoot; public renderRoot?: ShadowRoot;
public overrides: EwtInstallDialog["overrides"];
public static preload() { public static preload() {
import("./connect"); import("./connect");
} }

View File

@ -30,13 +30,20 @@ import { dialogStyles } from "./styles";
const ERROR_ICON = "⚠️"; const ERROR_ICON = "⚠️";
const OK_ICON = "🎉"; const OK_ICON = "🎉";
class EwtInstallDialog extends LitElement { export class EwtInstallDialog extends LitElement {
public port!: SerialPort; public port!: SerialPort;
public manifestPath!: string; public manifestPath!: string;
public logger: Logger = console; public logger: Logger = console;
public overrides?: {
checkSameFirmwareVersion?: (
manifest: Manifest,
deviceImprov: ImprovSerial["info"]
) => boolean;
};
private _manifest!: Manifest; private _manifest!: Manifest;
private _info?: ImprovSerial["info"]; private _info?: ImprovSerial["info"];
@ -877,7 +884,11 @@ class EwtInstallDialog extends LitElement {
* Return if the device runs same firmware as manifest. * Return if the device runs same firmware as manifest.
*/ */
private get _isSameFirmware() { 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;
} }
/** /**