Skip to content

Commit

Permalink
Fix "Manage Device Networking" toggle being disabled incorrectly (#1620)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Cameron (3539) <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2024
1 parent 4997ad9 commit 782929b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
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
Expand Down Expand Up @@ -104,17 +100,6 @@ public NetworkConfig(NetworkConfig config) {
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;
Expand All @@ -125,18 +110,12 @@ public String getEscapedInterfaceName() {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public UINetConfig(
super(config);
this.networkInterfaceNames = networkInterfaceNames;
this.networkingDisabled = networkingDisabled;
this.canManage = this.deviceCanManageNetwork();
}

public List<NMDeviceInfo> networkInterfaceNames;
public boolean networkingDisabled;
public boolean canManage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void initialize(boolean shouldManage) {
}

public void reinitialize() {
initialize(ConfigManager.getInstance().getConfig().getNetworkConfig().shouldManage());
initialize(ConfigManager.getInstance().getConfig().getNetworkConfig().shouldManage);

DataChangeService.getInstance()
.publishEvent(
Expand Down

0 comments on commit 782929b

Please sign in to comment.