Skip to content

Commit e6d68ce

Browse files
dhalbertclaude
andcommitted
Take ble-file-transfer-js 1.1.0 and drop the local read guard
1.1.0 rejects readFile()/listDir() when the link is down or drops mid-request: checkConnection() rethrows, and the response promise is installed before the request is written. That is what the _whileConnected() wrapper existed to do, so it goes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 8c66922 commit e6d68ce

3 files changed

Lines changed: 4 additions & 52 deletions

File tree

js/common/ble-file-transfer.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,6 @@ class FileTransferClient extends BLEFileTransferClient {
88
constructor(bleDevice, bufferSize, workflow = null) {
99
super(bleDevice, bufferSize);
1010
this._workflow = workflow;
11-
this._bleDevice = bleDevice;
12-
}
13-
14-
// Reject a read if the GATT link is already down, or drops while it is in
15-
// flight, instead of returning a promise that can never settle.
16-
//
17-
// Upstream readFile()/listDir() install their promise's reject handler
18-
// AFTER writing the request:
19-
//
20-
// await this._write(header);
21-
// await this._write(encoded);
22-
// let p = new Promise((resolve, reject) => {
23-
// this._resolve = resolve;
24-
// this._reject = reject; // too late
25-
// });
26-
//
27-
// On a dead link `_transfer` is null, so both writes throw; _write()
28-
// swallows the error and calls onDisconnected(), which has no `_reject` to
29-
// call yet. checkConnection() likewise catches its own failure and returns
30-
// normally rather than rethrowing, so the read proceeds regardless. The
31-
// returned promise is then never settled by anyone and the caller hangs --
32-
// which is what left the editor spinning on "Current Device Info".
33-
//
34-
// Bound on liveness rather than elapsed time: a large file read over BLE can
35-
// legitimately take tens of seconds, so a stopwatch would produce false
36-
// failures, while a dropped link is unambiguous.
37-
_whileConnected(operation) {
38-
const device = this._bleDevice;
39-
if (!device || !device.gatt || !device.gatt.connected) {
40-
return Promise.reject(new Error("Bluetooth device is not connected"));
41-
}
42-
return new Promise((resolve, reject) => {
43-
const onDisconnected = () => reject(new Error("Bluetooth device disconnected"));
44-
device.addEventListener("gattserverdisconnected", onDisconnected, {once: true});
45-
operation().then(resolve, reject).finally(() => {
46-
device.removeEventListener("gattserverdisconnected", onDisconnected);
47-
});
48-
});
49-
}
50-
51-
async readFile(path, raw = false) {
52-
return await this._whileConnected(() => super.readFile(path, raw));
53-
}
54-
55-
async listDir(path) {
56-
return await this._whileConnected(() => super.listDir(path));
5711
}
5812

5913
_signalMutatingOp() {

package-lock.json

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"vite-plugin-mkcert": "^2.1.0"
1515
},
1616
"dependencies": {
17-
"@adafruit/ble-file-transfer-js": "adafruit/ble-file-transfer-js#1.0.5",
17+
"@adafruit/ble-file-transfer-js": "adafruit/ble-file-transfer-js#1.1.0",
1818
"@adafruit/circuitpython-repl-js": "adafruit/circuitpython-repl-js#3.4.0",
1919
"@codemirror/lang-css": "^6.3.1",
2020
"@codemirror/lang-html": "^6.4.12",

0 commit comments

Comments
 (0)