Skip to content

Commit fe05faf

Browse files
committed
Pleasing sonar
1 parent 04b03ed commit fe05faf

File tree

4 files changed

+5
-148
lines changed

4 files changed

+5
-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/WebSerial.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const logHead = "[SERIAL]";
55

66
// Update streamAsyncIterable function
77
async function* streamAsyncIterable(reader, keepReadingFlag) {
8-
let lockReleased = false;
98
try {
109
while (keepReadingFlag()) {
1110
try {
@@ -22,9 +21,8 @@ async function* streamAsyncIterable(reader, keepReadingFlag) {
2221
} finally {
2322
// Only release the lock if we still have the reader and it hasn't been released
2423
try {
25-
if (reader && !reader.closed && !lockReleased) {
24+
if (!reader?.closed) {
2625
reader.releaseLock();
27-
lockReleased = true;
2826
}
2927
} catch (error) {
3028
console.warn(`${logHead} Error releasing reader lock:`, error);
@@ -276,15 +274,11 @@ class WebSerial extends EventTarget {
276274

277275
// Cancel reader first if it exists - this doesn't release the lock
278276
if (this.reader) {
279-
// try {
280277
try {
281278
await this.reader.cancel();
282279
} catch (e) {
283280
console.warn(`${logHead} Reader cancel error (can be ignored):`, e);
284281
}
285-
// } catch (e) {
286-
// // Ignore errors here - reader might already be canceled
287-
// }
288282
}
289283

290284
// Don't try to release the reader lock - streamAsyncIterable will handle it

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

-114
This file was deleted.

src/js/serial_backend.js

+2-24
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
}
@@ -812,15 +812,9 @@ export function reinitializeConnection() {
812812
if (CONFIGURATOR.virtualMode) {
813813
connectDisconnect();
814814
if (PortHandler.portPicker.autoConnect) {
815-
<<<<<<< HEAD
816815
return setTimeout(function () {
817816
$("a.connection_button__link").trigger("click");
818817
}, 500);
819-
=======
820-
clickConnectDisconnect();
821-
} else {
822-
return connectDisconnect();
823-
>>>>>>> d8b258f5 (Update autoconnect)
824818
}
825819
}
826820

@@ -832,20 +826,11 @@ export function reinitializeConnection() {
832826
// Send reboot command to the flight controller
833827
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
834828

835-
<<<<<<< HEAD
836829
if (currentPort.startsWith("bluetooth")) {
837830
if (!PortHandler.portPicker.autoConnect) {
838831
return setTimeout(function () {
839832
$("a.connection_button__link").trigger("click");
840833
}, 1500);
841-
=======
842-
if (CONFIGURATOR.bluetoothMode) {
843-
if (PortHandler.portPicker.autoConnect) {
844-
// Bluetooth devices are not disconnected when rebooting
845-
} else {
846-
// Disconnect from the device
847-
clickConnectDisconnect();
848-
>>>>>>> d8b258f5 (Update autoconnect)
849834
}
850835
}
851836

@@ -904,13 +889,6 @@ function showRebootDialog() {
904889
}
905890
}, 100);
906891

907-
const timeout = !CONFIGURATOR.bluetoothMode && !CONFIGURATOR.virtualMode && !CONFIGURATOR.manualMode ? 5000 : 1500;
908-
909-
// Set a maximum timeout for the reboot process (5 seconds)
910-
setTimeout(function () {
911-
executeCallbackOnce();
912-
}, timeout);
913-
914892
// Helper function to create the reboot dialog if it doesn't exist
915893
function createRebootProgressDialog() {
916894
const dialog = document.createElement("dialog");

0 commit comments

Comments
 (0)