Skip to content

Commit

Permalink
Fix port selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDosjani committed Oct 15, 2022
1 parent b5c2216 commit 6cffcf6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
19 changes: 12 additions & 7 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,15 @@ 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
};

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

setTimeout(function () {
this.usbCheckLoop = setTimeout(function () {
self.check();
}, TIMEOUT_CHECK);
};
Expand Down Expand Up @@ -196,7 +201,7 @@ PortHandler.check_usb_devices = function (callback) {
data: {isManual: true},
}));

self.portPickerElement.val('DFU').change();
self.portPickerElement.val('DFU').trigger('change');
self.setPortsInputWidth();
}
self.dfu_available = true;
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 6cffcf6

Please sign in to comment.