Skip to content

Commit af0f703

Browse files
committed
Fix MSDN browser
1 parent e0b44c0 commit af0f703

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
"message": "Show all serial devices (for manufacturers or development)",
110110
"description": "Do not filter serial devices using VID/PID values (for manufacturers or development)"
111111
},
112+
"useMdnsBrowser": {
113+
"message": "Use mDNS Browser Device discovery on network (experimental)",
114+
"description": "Enable mDNS Browser Device discovery in PortHandler (experimental)"
115+
},
112116
"showVirtualMode": {
113117
"message": "Enable virtual connection mode",
114118
"description": "Text for the option to enable or disable the virtual FC"

src/js/port_handler.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const PortHandler = new function () {
2121
this.dfu_available = false;
2222
this.port_available = false;
2323
this.showAllSerialDevices = false;
24+
this.useMdnsBrowser = false;
2425
this.showVirtualMode = false;
2526
};
2627

@@ -40,11 +41,14 @@ PortHandler.initialize = function () {
4041

4142
PortHandler.reinitialize = function () {
4243
this.initialPorts = false;
44+
4345
if (this.usbCheckLoop) {
4446
clearTimeout(this.usbCheckLoop);
4547
}
48+
4649
this.showVirtualMode = getConfig('showVirtualMode').showVirtualMode;
4750
this.showAllSerialDevices = getConfig('showAllSerialDevices').showAllSerialDevices;
51+
this.useMdnsBrowser = getConfig('useMdnsBrowser').useMdnsBrowser;
4852

4953
this.check(); // start listening, check after TIMEOUT_CHECK ms
5054
};
@@ -69,18 +73,23 @@ PortHandler.check_serial_devices = function () {
6973
const self = this;
7074

7175
serial.getDevices(function(cp) {
72-
73-
let currentPorts = [
74-
...cp,
75-
...(MdnsDiscovery.mdnsBrowser.services?.filter(s => s.txt.vendor === 'elrs' && s.txt.type === 'rx' && s.ready === true)
76-
.map(s => s.addresses.map(a => ({
77-
path: `tcp://${a}`,
78-
displayName: `${s.txt.target} - ${s.txt.version}`,
79-
fqdn: s.fqdn,
80-
vendorId: 0,
81-
productId: 0,
82-
}))).flat() ?? []),
83-
].filter(Boolean);
76+
let currentPorts = [];
77+
78+
if (self.useMdnsBrowser) {
79+
currentPorts = [
80+
...cp,
81+
...(MdnsDiscovery.mdnsBrowser.services?.filter(s => s.txt?.vendor === 'elrs' && s.txt?.type === 'rx' && s.ready === true)
82+
.map(s => s.addresses.map(a => ({
83+
path: `tcp://${a}`,
84+
displayName: `${s.txt?.target} - ${s.txt?.version}`,
85+
fqdn: s.fqdn,
86+
vendorId: 0,
87+
productId: 0,
88+
}))).flat() ?? []),
89+
].filter(Boolean);
90+
} else {
91+
currentPorts = cp;
92+
}
8493

8594
// auto-select port (only during initialization)
8695
if (!self.initialPorts) {

src/js/tabs/options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ options.initialize = function (callback) {
2121
TABS.options.initAnalyticsOptOut();
2222
TABS.options.initCliAutoComplete();
2323
TABS.options.initShowAllSerialDevices();
24+
TABS.options.initUseMdnsBrower();
2425
TABS.options.initShowVirtualMode();
2526
TABS.options.initCordovaForceComputerUI();
2627
TABS.options.initDarkTheme();
@@ -141,6 +142,17 @@ options.initShowVirtualMode = function() {
141142
});
142143
};
143144

145+
options.initUseMdnsBrower = function() {
146+
const useMdnsBrowserElement = $('div.useMdnsBrowser input');
147+
const result = getConfig('useMdnsBrowser');
148+
useMdnsBrowserElement
149+
.prop('checked', !!result.useMdnsBrowser)
150+
.on('change', () => {
151+
setConfig({ useMdnsBrowser: useMdnsBrowserElement.is(':checked') });
152+
PortHandler.reinitialize();
153+
});
154+
};
155+
144156
options.initCordovaForceComputerUI = function () {
145157
if (GUI.isCordova() && cordovaUI.canChangeUI) {
146158
const result = getConfig('cordovaForceComputerUI');

src/tabs/options.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
</div>
3636
<span class="freelabel" i18n="showAllSerialDevices"></span>
3737
</div>
38+
<div class="useMdnsBrowser margin-bottom">
39+
<div>
40+
<input type="checkbox" class="toggle" />
41+
</div>
42+
<span class="freelabel" i18n="useMdnsBrowser"></span>
43+
</div>
3844
<div class="showVirtualMode margin-bottom">
3945
<div>
4046
<input type="checkbox" class="toggle" />

0 commit comments

Comments
 (0)