Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Fix disconnect (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Nov 5, 2021
1 parent 24f234c commit 9cd1c74
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project is used by the [ESP Web Tools](https://github.com/esphome/esp-web-t
- Clone this repository.
- Install dependencies with `npm`
- Run `script/develop`
- Open http://localhost:5004/

## Fork

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esp-web-flasher",
"version": "3.2.0",
"version": "4.0.0",
"description": "Flash ESP devices using WebSerial",
"main": "dist/index.js",
"repository": "https://github.com/nabucasa/ESP-Web-flasher",
Expand Down
2 changes: 1 addition & 1 deletion script/develop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trap "kill 0" EXIT
# Run tsc once as rollup expects those files
npm exec -- tsc || true

npm exec -- serve &
npm exec -- serve -p 5004 &
npm exec -- tsc --watch &
npm exec -- rollup -c --watch &
wait
17 changes: 10 additions & 7 deletions src/esp_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export class ESPLoader extends EventTarget {
}
} catch (err) {
console.error("Read loop got disconnected");
// Disconnected!
this.connected = false;
this.dispatchEvent(new Event("disconnect"));
}
// Disconnected!
this.connected = false;
this.dispatchEvent(new Event("disconnect"));
this.logger.debug("Finished read loop");
}

Expand Down Expand Up @@ -1148,11 +1148,14 @@ export class ESPLoader extends EventTarget {
await this._parent.disconnect();
return;
}
if (this._reader) {
await this._reader.cancel();
}
await this.port.writable!.getWriter().close();
await this.port.close();
await new Promise((resolve) => {
if (!this._reader) {
resolve(undefined);
}
this.addEventListener("disconnect", resolve, { once: true });
this._reader!.cancel();
});
this.connected = false;
}
}
Expand Down

0 comments on commit 9cd1c74

Please sign in to comment.