Fix "Manage Device Networking" toggle being disabled incorrectly (#1620)

This fixes a bug introduced in #1592 that caused the Manage Device
Networking toggle to be disabled for systems where PhotonVision is
managing the network.

There is still a problem with the toggle defaulting to "off" and not
staying in the "on" position after settings are saved. I need help from
someone who understands the frontend to figure out why it keeps getting
set back to "off".

---------

Co-authored-by: Matt <matthew.morley.ca@gmail.com>
Co-authored-by: Cameron (3539) <theforgelover@gmail.com>
This commit is contained in:
Craig Schardt
2024-12-06 22:30:41 -06:00
committed by GitHub
parent 4997ad9115
commit 782929b006
3 changed files with 4 additions and 23 deletions

View File

@@ -21,12 +21,8 @@ import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
import org.photonvision.common.hardware.Platform;
import org.photonvision.common.networking.NetworkMode;
import org.photonvision.common.util.file.JacksonUtils;
public class NetworkConfig {
// Can be an integer team number, or an IP address
@@ -104,17 +100,6 @@ public class NetworkConfig {
config.matchCamerasOnlyByPath);
}
public Map<String, Object> toHashMap() {
try {
var ret = new ObjectMapper().convertValue(this, JacksonUtils.UIMap.class);
ret.put("canManage", this.deviceCanManageNetwork());
return ret;
} catch (Exception e) {
e.printStackTrace();
return new HashMap<>();
}
}
@JsonIgnore
public String getPhysicalInterfaceName() {
return this.networkManagerIface;
@@ -125,18 +110,12 @@ public class NetworkConfig {
return "\"" + networkManagerIface + "\"";
}
@JsonIgnore
public boolean shouldManage() {
return this.shouldManage;
}
@JsonIgnore
public void setShouldManage(boolean shouldManage) {
this.shouldManage = shouldManage && this.deviceCanManageNetwork();
}
@JsonIgnore
private boolean deviceCanManageNetwork() {
protected boolean deviceCanManageNetwork() {
return Platform.isLinux();
}

View File

@@ -27,8 +27,10 @@ public class UINetConfig extends NetworkConfig {
super(config);
this.networkInterfaceNames = networkInterfaceNames;
this.networkingDisabled = networkingDisabled;
this.canManage = this.deviceCanManageNetwork();
}
public List<NMDeviceInfo> networkInterfaceNames;
public boolean networkingDisabled;
public boolean canManage;
}

View File

@@ -113,7 +113,7 @@ public class NetworkManager {
}
public void reinitialize() {
initialize(ConfigManager.getInstance().getConfig().getNetworkConfig().shouldManage());
initialize(ConfigManager.getInstance().getConfig().getNetworkConfig().shouldManage);
DataChangeService.getInstance()
.publishEvent(