Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes #30

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ export const startProvisioning = async (button: SerialLaunchButton) => {
let port: SerialPort | undefined;
try {
port = await navigator.serial.requestPort();
} catch (err) {
console.error("User cancelled request", err);
} catch (err: any) {
if ((err as DOMException).name === "NotFoundError") {
return;
}
alert(`Error: ${err.message}`);
return;
}

Expand Down
8 changes: 5 additions & 3 deletions src/serial-provision-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,19 @@ class SerialProvisionDialog extends LitElement {
}

private async _provision() {
this._hasProvisioned = true;
this._busy = true;
try {
// No need to do error handling because we listen for `error-changed` events
await this._client!.provision(
this._selectedSsid === -1
? this._inputSSID.value
: this._ssids![this._selectedSsid].name,
this._inputPassword.value
);
this._hasProvisioned = true;
this._showProvisionForm = false;
} catch (err) {
// No need to do error handling because we listen for `error-changed` events
console.log(err);
} finally {
this._busy = false;
}
Expand Down Expand Up @@ -343,7 +346,6 @@ class SerialProvisionDialog extends LitElement {
const client = new ImprovSerial(this.port!, this.logger);
client.addEventListener("state-changed", () => {
this._state = "IMPROV-STATE";
this._showProvisionForm = false;
this.requestUpdate();
});
client.addEventListener("error-changed", () => this.requestUpdate());
Expand Down
10 changes: 7 additions & 3 deletions src/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ export class ImprovSerial extends EventTarget {
this.nextUrl = response[0];
}

public async scan() {
const ssids = await this._sendRPCWithMultipleResponses(
public async scan(): Promise<Ssid[]> {
const results = await this._sendRPCWithMultipleResponses(
ImprovSerialRPCCommand.REQUEST_WIFI_NETWORKS,
[]
);
return ssids.map(([name, rssi, secured]) => ({
const ssids = results.map(([name, rssi, secured]) => ({
name,
rssi: parseInt(rssi),
secured: secured === "YES",
}));
ssids.sort((a, b) =>
a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase())
);
return ssids;
}

private _sendRPC(command: ImprovSerialRPCCommand, data: number[]) {
Expand Down