From f08556be30ee8a8bf436664049de8183c52cadae Mon Sep 17 00:00:00 2001 From: Fabricio Silva Date: Tue, 11 Jul 2023 04:23:37 +0100 Subject: [PATCH] WebUI: Preserve the network interfaces when down PR #19286. --- src/webui/api/appcontroller.cpp | 7 +++++-- src/webui/www/private/views/preferences.html | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 860634b8f..c00508ba6 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -320,8 +320,10 @@ void AppController::preferencesAction() data[u"memory_working_set_limit"_s] = app()->memoryWorkingSetLimit(); // Current network interface data[u"current_network_interface"_s] = session->networkInterface(); + // Current network interface name + data[u"current_interface_name"_s] = session->networkInterfaceName(); // Current network interface address - data[u"current_interface_address"_s] = BitTorrent::Session::instance()->networkInterfaceAddress(); + data[u"current_interface_address"_s] = session->networkInterfaceAddress(); // Save resume data interval data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval(); // Recheck completed torrents @@ -845,7 +847,8 @@ void AppController::setPreferencesAction() const QString ifaceName = (ifacesIter != ifaces.cend()) ? ifacesIter->humanReadableName() : QString {}; session->setNetworkInterface(ifaceValue); - session->setNetworkInterfaceName(ifaceName); + if (!ifaceName.isEmpty() || ifaceValue.isEmpty()) + session->setNetworkInterfaceName(ifaceName); } // Current network interface address if (hasKey(u"current_interface_address"_s)) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 4c6d22a0c..fb0374f68 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1749,7 +1749,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD }; // Advanced Tab - const updateNetworkInterfaces = function(default_iface) { + const updateNetworkInterfaces = function(default_iface, default_iface_name) { const url = 'api/v2/app/networkInterfaceList'; $('networkInterface').empty(); new Request.JSON({ @@ -1760,9 +1760,13 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD alert("Could not contact qBittorrent"); }, onSuccess: function(ifaces) { - if (!ifaces) + if (!Array.isArray(ifaces)) return; + // add the current network interface to the options if needed + if (default_iface && !ifaces.some((item) => item.value === default_iface)) + ifaces.push({ name: default_iface_name || default_iface, value: default_iface }); + $('networkInterface').options.add(new Option('QBT_TR(Any interface)QBT_TR[CONTEXT=OptionsDialog]', '')); ifaces.forEach(function(item, index) { $('networkInterface').options.add(new Option(item.name, item.value)); @@ -2144,7 +2148,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD // qBittorrent section $('resumeDataStorageType').setProperty('value', pref.resume_data_storage_type); $('memoryWorkingSetLimit').setProperty('value', pref.memory_working_set_limit); - updateNetworkInterfaces(pref.current_network_interface); + updateNetworkInterfaces(pref.current_network_interface, pref.current_interface_name); updateInterfaceAddresses(pref.current_network_interface, pref.current_interface_address); $('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval); $('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents);