Skip to content

Commit

Permalink
Fix port selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDosjani committed Sep 23, 2022
1 parent db99a98 commit e4e08fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/js/port_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const PortHandler = new function () {
this.port_available = false;
this.showAllSerialDevices = false;
this.showVirtualMode = false;
this.usbCheckLoop = 0;
};

PortHandler.initialize = function () {
Expand All @@ -26,9 +27,6 @@ PortHandler.initialize = function () {
this.selectList = document.querySelector(portPickerElementSelector);
this.initialWidth = this.selectList.offsetWidth + 12;

this.showVirtualMode = ConfigStorage.get('showVirtualMode').showVirtualMode;
this.showAllSerialDevices = ConfigStorage.get('showAllSerialDevices').showAllSerialDevices;

// fill dropdown with version numbers
generateVirtualApiVersions();

Expand Down Expand Up @@ -120,8 +118,16 @@ PortHandler.initialize = function () {
}
}, MDNS_INTERVAL);

// start listening, check after TIMEOUT_CHECK ms
this.check();
this.reinitialize(); // just to prevent code redundancy
};

PortHandler.reinitialize = function () {
this.initialPorts = false;
clearTimeout(this.check_loop);
this.showVirtualMode = ConfigStorage.get('showVirtualMode').showVirtualMode;
this.showAllSerialDevices = ConfigStorage.get('showAllSerialDevices').showAllSerialDevices;
this.check(); // start listening, check after TIMEOUT_CHECK ms
this.portPickerElement.change();
};

PortHandler.check = function () {
Expand All @@ -135,7 +141,7 @@ PortHandler.check = function () {
self.check_serial_devices();
}

setTimeout(function () {
this.usbCheckLoop = setTimeout(function () {
self.check();
}, TIMEOUT_CHECK);
};
Expand All @@ -162,6 +168,7 @@ PortHandler.check_serial_devices = function () {
currentPorts = self.updatePortSelect(currentPorts);
self.selectPort(currentPorts);
self.initialPorts = currentPorts;
self.portPickerElement.change();
} else {
self.removePort(currentPorts);
self.detectPort(currentPorts);
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const firmware_flasher = {
};

firmware_flasher.initialize = function (callback) {
PortHandler.reinitialize(); //select recognized board

const self = this;

if (GUI.active_tab !== 'firmware_flasher') {
Expand Down
11 changes: 6 additions & 5 deletions src/js/tabs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ options.initShowAllSerialDevices = function() {
const result = ConfigStorage.get('showAllSerialDevices');
showAllSerialDevicesElement
.prop('checked', !!result.showAllSerialDevices)
.on('change', () => ConfigStorage.set({ showAllSerialDevices: showAllSerialDevicesElement.is(':checked') }))
.trigger('change');
.on('change', () => {
ConfigStorage.set({ showAllSerialDevices: showAllSerialDevicesElement.is(':checked') });
PortHandler.reinitialize();
});
};

options.initShowVirtualMode = function() {
Expand All @@ -144,9 +146,8 @@ options.initShowVirtualMode = function() {
.prop('checked', !!result.showVirtualMode)
.on('change', () => {
ConfigStorage.set({ showVirtualMode: showVirtualModeElement.is(':checked') });
PortHandler.initialPorts = false;
})
.trigger('change');
PortHandler.reinitialize();
});
};

options.initCordovaForceComputerUI = function () {
Expand Down

0 comments on commit e4e08fa

Please sign in to comment.