tasmota-esp-web-tools
Version:
Web tools for ESP devices
44 lines (39 loc) • 1.03 kB
text/typescript
import type { InstallButton } from "./install-button.js";
export const connect = async (button: InstallButton) => {
import("./install-dialog.js");
let port: SerialPort | undefined;
try {
port = await navigator.serial.requestPort();
} catch (err: any) {
if ((err as DOMException).name === "NotFoundError") {
import("./no-port-picked/index").then((mod) =>
mod.openNoPortPickedDialog(() => connect(button)),
);
return;
}
alert(`Error: ${err.message}`);
return;
}
if (!port) {
return;
}
try {
await port.open({ baudRate: 115200 });
} catch (err: any) {
alert(err.message);
return;
}
const el = document.createElement("ewt-install-dialog");
el.port = port;
el.manifestPath = button.manifest || button.getAttribute("manifest")!;
el.overrides = button.overrides;
el.firmwareFile = button.firmwareFile;
el.addEventListener(
"closed",
() => {
port!.close();
},
{ once: true },
);
document.body.appendChild(el);
};