|
|
@ -33,7 +33,7 @@ export class TransportWebSerial implements Types.Transport { |
|
|
// Set up the pipe with abort signal for clean cancellation
|
|
|
// Set up the pipe with abort signal for clean cancellation
|
|
|
this.pipePromise = Utils.toDeviceStream.readable.pipeTo( |
|
|
this.pipePromise = Utils.toDeviceStream.readable.pipeTo( |
|
|
connection.writable, |
|
|
connection.writable, |
|
|
{ signal: this.abortController.signal } |
|
|
{ signal: this.abortController.signal }, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
this._toDevice = Utils.toDeviceStream.writable; |
|
|
this._toDevice = Utils.toDeviceStream.writable; |
|
|
@ -58,31 +58,30 @@ export class TransportWebSerial implements Types.Transport { |
|
|
async disconnect() { |
|
|
async disconnect() { |
|
|
try { |
|
|
try { |
|
|
this.abortController.abort(); |
|
|
this.abortController.abort(); |
|
|
|
|
|
|
|
|
if (this.pipePromise) { |
|
|
if (this.pipePromise) { |
|
|
try { |
|
|
try { |
|
|
await this.pipePromise; |
|
|
await this.pipePromise; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
if (error instanceof Error && error.name !== 'AbortError') { |
|
|
if (error instanceof Error && error.name !== "AbortError") { |
|
|
throw error; |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Cancel any remaining streams
|
|
|
// Cancel any remaining streams
|
|
|
if (this._fromDevice && this._fromDevice.locked) { |
|
|
if (this._fromDevice?.locked) { |
|
|
try { |
|
|
try { |
|
|
await this._fromDevice.cancel(); |
|
|
await this._fromDevice.cancel(); |
|
|
} catch (error) { |
|
|
} catch { |
|
|
// Stream cancellation might fail if already cancelled
|
|
|
// Stream cancellation might fail if already cancelled
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await this.connection.close(); |
|
|
await this.connection.close(); |
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
// If we can't close cleanly, let the browser handle cleanup
|
|
|
// If we can't close cleanly, let the browser handle cleanup
|
|
|
console.warn('Could not cleanly disconnect serial port:', error); |
|
|
console.warn("Could not cleanly disconnect serial port:", error); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -93,11 +92,11 @@ export class TransportWebSerial implements Types.Transport { |
|
|
async reconnect() { |
|
|
async reconnect() { |
|
|
// Create a new AbortController for the new connection
|
|
|
// Create a new AbortController for the new connection
|
|
|
this.abortController = new AbortController(); |
|
|
this.abortController = new AbortController(); |
|
|
|
|
|
|
|
|
// Re-establish the pipe connection
|
|
|
// Re-establish the pipe connection
|
|
|
this.pipePromise = Utils.toDeviceStream.readable.pipeTo( |
|
|
this.pipePromise = Utils.toDeviceStream.readable.pipeTo( |
|
|
this.connection.writable, |
|
|
this.connection.writable, |
|
|
{ signal: this.abortController.signal } |
|
|
{ signal: this.abortController.signal }, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|