Make NMDeviceInfo a record

This commit is contained in:
Gold856
2025-04-14 18:43:53 -04:00
committed by Matt Morley
parent 1fb02a477d
commit 20e2fe46ba
2 changed files with 15 additions and 24 deletions

View File

@@ -77,21 +77,22 @@ public class NetworkManager {
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
for (NMDeviceInfo deviceInfo : ethernetDevices) {
activeConnections.put(
deviceInfo.devName, NetworkUtils.getActiveConnection(deviceInfo.devName));
monitorDevice(deviceInfo.devName, 5000);
deviceInfo.devName(), NetworkUtils.getActiveConnection(deviceInfo.devName()));
monitorDevice(deviceInfo.devName(), 5000);
}
var physicalDevices = NetworkUtils.getAllActiveWiredInterfaces();
var config = ConfigManager.getInstance().getConfig().getNetworkConfig();
if (physicalDevices.stream().noneMatch(it -> (it.devName.equals(config.networkManagerIface)))) {
if (physicalDevices.stream()
.noneMatch(it -> (it.devName().equals(config.networkManagerIface)))) {
try {
// if the configured interface isn't in the list of available ones, select one that is
var iFace = physicalDevices.stream().findFirst().orElseThrow();
logger.warn(
"The configured interface doesn't match any available interface. Applying configuration to "
+ iFace.devName);
+ iFace.devName());
// update NetworkConfig with found interface
config.networkManagerIface = iFace.devName;
config.networkManagerIface = iFace.devName();
ConfigManager.getInstance().requestSave();
} catch (NoSuchElementException e) {
// if there are no available interfaces, go with the one from settings

View File

@@ -53,26 +53,16 @@ public class NetworkUtils {
}
}
public static class NMDeviceInfo {
/**
* Contains data about network devices retrieved from "nmcli device show"
*
* @param connName The human-readable name used by "nmcli con"
* @param devName The underlying device name, used by dhclient
* @param nmType The NetworkManager device type
*/
public static record NMDeviceInfo(String connName, String devName, NMType nmType) {
public NMDeviceInfo(String c, String d, String type) {
connName = c;
devName = d;
nmType = NMType.typeForString(type);
}
public final String connName; // Human-readable name used by "nmcli con"
public final String devName; // underlying device, used by dhclient
public final NMType nmType;
@Override
public String toString() {
return "NMDeviceInfo [connName="
+ connName
+ ", devName="
+ devName
+ ", nmType="
+ nmType
+ "]";
this(c, d, NMType.typeForString(type));
}
}