From e9511f60047e61a0411264838194cf4d78246688 Mon Sep 17 00:00:00 2001 From: tyeth Date: Sun, 26 Oct 2025 02:07:06 +0000 Subject: [PATCH 1/2] wip(wifi workflow): DELETE method available doesn't represent writable on CPY 10.0.3 lilygot tdisplay S3, switch to fs json like circup --- js/common/web-file-transfer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/common/web-file-transfer.js b/js/common/web-file-transfer.js index cfedb9d..fb8564c 100644 --- a/js/common/web-file-transfer.js +++ b/js/common/web-file-transfer.js @@ -7,7 +7,11 @@ class FileTransferClient { async readOnly() { await this._checkConnection(); - return !this._allowedMethods.includes('DELETE'); + console.log("Checking read only"); + const response = await this._fetch("/fs/", {method: "GET", headers: {"Accept": "application/json"}}) + const result = await response.json(); + //TODO: Tyeth: cache this value until reconnection, as listdir / connect already fetch it + return result.writable === undefined || result.writable === false || !this._allowedMethods.includes("DELETE"); } async _checkConnection() { @@ -15,6 +19,7 @@ class FileTransferClient { throw new Error("Unable to perform file operation. Not Connected."); } + //TODO: Tyeth: reset this on reconnection if (this._allowedMethods === null) { const status = await this._fetch("/fs/", {method: "OPTIONS"}); this._allowedMethods = status.headers.get("Access-Control-Allow-Methods").split(/,/).map(method => {return method.trim().toUpperCase();}); From 90ec8644a2a3521893515b94c2065d510b354ec6 Mon Sep 17 00:00:00 2001 From: tyeth Date: Mon, 27 Oct 2025 15:43:11 +0000 Subject: [PATCH 2/2] fix(usb): disconnect handler can fail in various places --- js/workflows/usb.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index 7b4ca9f..d441fed 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -53,16 +53,28 @@ class USBWorkflow extends Workflow { async onDisconnected(e, reconnect = true) { if (this.reader) { - await this.reader.cancel(); + try { + await this.reader.cancel(); + } catch (error) { + console.warn("Error calling reader.cancel:", error); + } this.reader = null; } if (this.writer) { - await this.writer.releaseLock(); + try { + await this.writer.releaseLock(); + } catch (error) { + console.warn("Error calling writer.releaseLock:", error); + } this.writer = null; } if (this._serialDevice) { - await this._serialDevice.close(); + try { + await this._serialDevice.close(); + } catch (error) { + console.warn("Error calling _serialDevice.close:", error); + } this._serialDevice = null; } @@ -273,7 +285,11 @@ class USBWorkflow extends Workflow { device.addEventListener("message", this._messageCallback); let onDisconnect = async (e) => { - await this.onDisconnected(e, false); + try { + await this.onDisconnected(e, false); + } catch (error) { + console.warn("Error calling onDisconnected (maybe already disconnected):", error); + } }; device.removeEventListener("disconnect", onDisconnect); device.addEventListener("disconnect", onDisconnect);