mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-30 08:04:04 +00:00
handle removing of networks we are no longer connected to from the UI
This commit is contained in:
parent
78a8ceda0e
commit
3c248ec61a
@ -21,7 +21,7 @@ namespace WinUI
|
||||
public partial class NetworkInfoView : UserControl
|
||||
{
|
||||
private APIHandler handler;
|
||||
private ZeroTierNetwork network;
|
||||
public ZeroTierNetwork network;
|
||||
|
||||
public NetworkInfoView(APIHandler handler, ZeroTierNetwork network)
|
||||
{
|
||||
@ -31,19 +31,41 @@ namespace WinUI
|
||||
this.network = network;
|
||||
|
||||
UpdateNetworkData();
|
||||
|
||||
allowDefault.Checked += AllowDefault_CheckStateChanged;
|
||||
allowDefault.Unchecked += AllowDefault_CheckStateChanged;
|
||||
allowGlobal.Checked += AllowGlobal_CheckStateChanged;
|
||||
allowGlobal.Unchecked += AllowGlobal_CheckStateChanged;
|
||||
allowManaged.Checked += AllowManaged_CheckStateChanged;
|
||||
allowManaged.Unchecked += AllowManaged_CheckStateChanged;
|
||||
}
|
||||
|
||||
private void UpdateNetworkData()
|
||||
{
|
||||
this.networkId.Text = network.NetworkId;
|
||||
this.networkName.Text = network.NetworkName;
|
||||
this.networkStatus.Text = network.NetworkStatus;
|
||||
this.networkType.Text = network.NetworkType;
|
||||
this.macAddress.Text = network.MacAddress;
|
||||
this.mtu.Text = network.MTU.ToString();
|
||||
|
||||
if (this.networkId.Text != network.NetworkId)
|
||||
this.networkId.Text = network.NetworkId;
|
||||
|
||||
if (this.networkName.Text != network.NetworkName)
|
||||
this.networkName.Text = network.NetworkName;
|
||||
|
||||
if (this.networkStatus.Text != network.NetworkStatus)
|
||||
this.networkStatus.Text = network.NetworkStatus;
|
||||
|
||||
if (this.networkType.Text != network.NetworkType)
|
||||
this.networkType.Text = network.NetworkType;
|
||||
|
||||
if (this.macAddress.Text != network.MacAddress)
|
||||
this.macAddress.Text = network.MacAddress;
|
||||
|
||||
if (this.mtu.Text != network.MTU.ToString())
|
||||
this.mtu.Text = network.MTU.ToString();
|
||||
|
||||
this.broadcastEnabled.Text = (network.BroadcastEnabled ? "ENABLED" : "DISABLED");
|
||||
this.bridgingEnabled.Text = (network.Bridge ? "ENABLED" : "DISABLED");
|
||||
this.deviceName.Text = network.DeviceName;
|
||||
|
||||
if (this.deviceName.Text != network.DeviceName)
|
||||
this.deviceName.Text = network.DeviceName;
|
||||
|
||||
string iplist = "";
|
||||
for (int i = 0; i < network.AssignedAddresses.Length; ++i)
|
||||
@ -53,19 +75,12 @@ namespace WinUI
|
||||
iplist += "\n";
|
||||
}
|
||||
|
||||
this.managedIps.Text = iplist;
|
||||
if (this.managedIps.Text != iplist)
|
||||
this.managedIps.Text = iplist;
|
||||
|
||||
this.allowDefault.IsChecked = network.AllowDefault;
|
||||
this.allowGlobal.IsChecked = network.AllowGlobal;
|
||||
this.allowManaged.IsChecked = network.AllowManaged;
|
||||
|
||||
allowDefault.Checked += AllowDefault_CheckStateChanged;
|
||||
allowDefault.Unchecked += AllowDefault_CheckStateChanged;
|
||||
allowGlobal.Checked += AllowGlobal_CheckStateChanged;
|
||||
allowGlobal.Unchecked += AllowGlobal_CheckStateChanged;
|
||||
allowManaged.Checked += AllowManaged_CheckStateChanged;
|
||||
allowManaged.Unchecked += AllowManaged_CheckStateChanged;
|
||||
|
||||
}
|
||||
|
||||
public bool HasNetwork(ZeroTierNetwork network)
|
||||
@ -76,6 +91,13 @@ namespace WinUI
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetNetworkInfo(ZeroTierNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
|
||||
UpdateNetworkData();
|
||||
}
|
||||
|
||||
private void leaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
handler.LeaveNetwork(network.NetworkId);
|
||||
|
@ -34,19 +34,74 @@ namespace WinUI
|
||||
|
||||
public void setNetworks(List<ZeroTierNetwork> networks)
|
||||
{
|
||||
this.wrapPanel.Children.Clear();
|
||||
if (networks == null)
|
||||
{
|
||||
this.wrapPanel.Children.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < networks.Count; ++i)
|
||||
foreach (ZeroTierNetwork network in networks)
|
||||
{
|
||||
this.wrapPanel.Children.Add(
|
||||
new NetworkInfoView(
|
||||
handler,
|
||||
networks.ElementAt<ZeroTierNetwork>(i)));
|
||||
NetworkInfoView view = ChildWithNetwork(network);
|
||||
if (view != null)
|
||||
{
|
||||
view.SetNetworkInfo(network);
|
||||
}
|
||||
else
|
||||
{
|
||||
wrapPanel.Children.Add(
|
||||
new NetworkInfoView(
|
||||
handler,
|
||||
network));
|
||||
}
|
||||
}
|
||||
|
||||
// remove networks we're no longer joined to.
|
||||
List<ZeroTierNetwork> tmpList = GetNetworksFromChildren();
|
||||
foreach (ZeroTierNetwork n in networks)
|
||||
{
|
||||
if (tmpList.Contains(n))
|
||||
{
|
||||
tmpList.Remove(n);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ZeroTierNetwork n in tmpList)
|
||||
{
|
||||
NetworkInfoView view = ChildWithNetwork(n);
|
||||
if (view != null)
|
||||
{
|
||||
wrapPanel.Children.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkInfoView ChildWithNetwork(ZeroTierNetwork network)
|
||||
{
|
||||
List<NetworkInfoView> list = wrapPanel.Children.OfType<NetworkInfoView>().ToList();
|
||||
|
||||
foreach (NetworkInfoView view in list)
|
||||
{
|
||||
if (view.HasNetwork(network))
|
||||
{
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ZeroTierNetwork> GetNetworksFromChildren()
|
||||
{
|
||||
List<ZeroTierNetwork> networks = new List<ZeroTierNetwork>(wrapPanel.Children.Count);
|
||||
|
||||
List<NetworkInfoView> list = wrapPanel.Children.OfType<NetworkInfoView>().ToList();
|
||||
foreach (NetworkInfoView n in list)
|
||||
{
|
||||
networks.Add(n.network);
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user