WebUI: Preserve the network interfaces when down

PR #19286.
This commit is contained in:
Fabricio Silva 2023-07-11 04:23:37 +01:00 committed by GitHub
parent 488464731d
commit f08556be30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -320,8 +320,10 @@ void AppController::preferencesAction()
data[u"memory_working_set_limit"_s] = app()->memoryWorkingSetLimit(); data[u"memory_working_set_limit"_s] = app()->memoryWorkingSetLimit();
// Current network interface // Current network interface
data[u"current_network_interface"_s] = session->networkInterface(); data[u"current_network_interface"_s] = session->networkInterface();
// Current network interface name
data[u"current_interface_name"_s] = session->networkInterfaceName();
// Current network interface address // 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 // Save resume data interval
data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval(); data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval();
// Recheck completed torrents // Recheck completed torrents
@ -845,6 +847,7 @@ void AppController::setPreferencesAction()
const QString ifaceName = (ifacesIter != ifaces.cend()) ? ifacesIter->humanReadableName() : QString {}; const QString ifaceName = (ifacesIter != ifaces.cend()) ? ifacesIter->humanReadableName() : QString {};
session->setNetworkInterface(ifaceValue); session->setNetworkInterface(ifaceValue);
if (!ifaceName.isEmpty() || ifaceValue.isEmpty())
session->setNetworkInterfaceName(ifaceName); session->setNetworkInterfaceName(ifaceName);
} }
// Current network interface address // Current network interface address

View file

@ -1749,7 +1749,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}; };
// Advanced Tab // Advanced Tab
const updateNetworkInterfaces = function(default_iface) { const updateNetworkInterfaces = function(default_iface, default_iface_name) {
const url = 'api/v2/app/networkInterfaceList'; const url = 'api/v2/app/networkInterfaceList';
$('networkInterface').empty(); $('networkInterface').empty();
new Request.JSON({ new Request.JSON({
@ -1760,9 +1760,13 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
alert("Could not contact qBittorrent"); alert("Could not contact qBittorrent");
}, },
onSuccess: function(ifaces) { onSuccess: function(ifaces) {
if (!ifaces) if (!Array.isArray(ifaces))
return; 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]', '')); $('networkInterface').options.add(new Option('QBT_TR(Any interface)QBT_TR[CONTEXT=OptionsDialog]', ''));
ifaces.forEach(function(item, index) { ifaces.forEach(function(item, index) {
$('networkInterface').options.add(new Option(item.name, item.value)); $('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 // qBittorrent section
$('resumeDataStorageType').setProperty('value', pref.resume_data_storage_type); $('resumeDataStorageType').setProperty('value', pref.resume_data_storage_type);
$('memoryWorkingSetLimit').setProperty('value', pref.memory_working_set_limit); $('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); updateInterfaceAddresses(pref.current_network_interface, pref.current_interface_address);
$('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval); $('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval);
$('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents); $('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents);