Skip to content

Commit 21f06d3

Browse files
committed
Pleasing sonar
1 parent 605efae commit 21f06d3

File tree

4 files changed

+14
-148
lines changed

4 files changed

+14
-148
lines changed

src/js/port_handler.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ PortHandler.removedSerialDevice = function (device) {
122122
PortHandler.addedUsbDevice = function (device) {
123123
this.updateDeviceList("usb").then(() => {
124124
const selectedPort = this.selectActivePort(device);
125-
console.log(`${this.logHead} Added USB device:`, device, selectedPort);
126-
if (selectedPort === device.path) {
127-
// Emit an event with the proper type for backward compatibility
125+
if (selectedPort === device?.path) {
126+
// Send event when the port handler auto selects a new USB device
128127
EventBus.$emit("port-handler:auto-select-usb-device", selectedPort);
129128
}
130129
});

src/js/protocols/__tests__/WebBluetooth.test.js

-114
This file was deleted.

src/js/serial.js

+10-29
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,11 @@ class Serial extends EventTarget {
224224

225225
// If we're connected to a different port, disconnect first
226226
console.log(`${this.logHead} Connected to a different port, disconnecting first`);
227-
this.disconnect((success) => {
228-
if (success) {
229-
// Now connect to the new port
230-
console.log(`${this.logHead} Reconnecting to new port:`, path);
231-
this._protocol.connect(path, options);
232-
} else {
233-
console.error(`${this.logHead} Failed to disconnect before reconnecting`);
234-
return false;
235-
}
236-
});
227+
const success = await this.disconnect();
228+
if (!success) {
229+
console.error(`${this.logHead} Failed to disconnect before reconnecting`);
230+
return false;
231+
}
237232

238233
console.log(`${this.logHead} Reconnecting to new port:`, path);
239234
return this._protocol.connect(path, options);
@@ -269,30 +264,16 @@ class Serial extends EventTarget {
269264
}
270265

271266
// Create a promise that will resolve/reject based on the protocol's disconnect result
272-
return new Promise((resolve) => {
273-
// Call the protocol's disconnect with a callback that will resolve our promise
274-
this._protocol.disconnect((success) => {
275-
if (success) {
276-
console.log(`${this.logHead} Disconnection successful`);
277-
} else {
278-
console.error(`${this.logHead} Disconnection failed`);
279-
}
280-
281-
// Call original callback
282-
if (callback) {
283-
callback(success);
284-
}
285-
286-
// Resolve our promise with the success value
287-
resolve(success);
288-
});
289-
});
267+
const success = await this._protocol.disconnect();
268+
269+
if (callback) callback(success);
270+
return success;
290271
} catch (error) {
291272
console.error(`${this.logHead} Error during disconnect:`, error);
292273
if (callback) {
293274
callback(false);
294275
}
295-
return false;
276+
return Promise.resolve(false);
296277
}
297278
}
298279

src/js/serial_backend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function initializeSerialBackend() {
6161
!GUI.connecting_to &&
6262
GUI.active_tab !== "firmware_flasher" &&
6363
((PortHandler.portPicker.autoConnect && !["manual", "virtual"].includes(device)) ||
64-
Date.now() - rebootTimestamp > REBOOT_CONNECT_MAX_TIME_MS)
64+
Date.now() - rebootTimestamp < REBOOT_CONNECT_MAX_TIME_MS)
6565
) {
6666
connectDisconnect();
6767
}
@@ -73,7 +73,7 @@ export function initializeSerialBackend() {
7373
!GUI.connecting_to &&
7474
GUI.active_tab !== "firmware_flasher" &&
7575
((PortHandler.portPicker.autoConnect && !["manual", "virtual"].includes(device)) ||
76-
Date.now() - rebootTimestamp > REBOOT_CONNECT_MAX_TIME_MS)
76+
Date.now() - rebootTimestamp < REBOOT_CONNECT_MAX_TIME_MS)
7777
) {
7878
connectDisconnect();
7979
}

0 commit comments

Comments
 (0)