diff --git a/windows/WinUI/NetworkMonitor.cs b/windows/WinUI/NetworkMonitor.cs
index b8d2c9461..de5543f6e 100644
--- a/windows/WinUI/NetworkMonitor.cs
+++ b/windows/WinUI/NetworkMonitor.cs
@@ -101,6 +101,10 @@ namespace WinUI
{
n.IsConnected = true;
}
+ else
+ {
+ n.IsConnected = false;
+ }
}
_nwCb(_knownNetworks);
diff --git a/windows/WinUI/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml
index 065919fd1..bbc176497 100644
--- a/windows/WinUI/ToolbarItem.xaml
+++ b/windows/WinUI/ToolbarItem.xaml
@@ -12,7 +12,7 @@
-
+
@@ -25,16 +25,32 @@
PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen">
-
-
-
-
-
-
diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs
index fc6b6406d..15aeb24bf 100644
--- a/windows/WinUI/ToolbarItem.xaml.cs
+++ b/windows/WinUI/ToolbarItem.xaml.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -23,18 +25,17 @@ namespace WinUI
///
/// Interaction logic for ToolbarItem.xaml
///
- public partial class ToolbarItem : Window
+ public partial class ToolbarItem : Window, INotifyPropertyChanged
{
private APIHandler handler = APIHandler.Instance;
private NetworkListView netListView = null;
- private List networkList = null;
private NetworkMonitor mon = NetworkMonitor.Instance;
- private ObservableCollection _networkCollection = new ObservableCollection();
+ private ObservableCollection _networkCollection = new ObservableCollection();
- public ObservableCollection NetworkCollection
+ public ObservableCollection NetworkCollection
{
get { return _networkCollection; }
set { _networkCollection = value; }
@@ -54,27 +55,30 @@ namespace WinUI
mon.UnsubscribeStatusUpdates(updateStatus);
}
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
private void updateNetworks(List networks)
{
if (networks != null)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
+ NetworkCollection.Clear();
foreach (ZeroTierNetwork n in networks)
{
- int index = _networkCollection.IndexOf(n);
+ MenuItem item = new MenuItem();
+ item.Header = n.Title;
+ item.DataContext = n;
+ item.IsChecked = n.IsConnected;
+ item.Click += ToolbarItem_NetworkClicked;
- if (index == -1)
- {
- _networkCollection.Add(n);
- }
- else
- {
- _networkCollection[index] = n;
- }
+ NetworkCollection.Add(item);
}
-
- this.networkList = networks;
}));
}
}
@@ -130,5 +134,25 @@ namespace WinUI
{
}
+
+ private void ToolbarItem_NetworkClicked(object sender, System.Windows.RoutedEventArgs e)
+ {
+ if(sender.GetType() == typeof(MenuItem))
+ {
+ MenuItem item = e.Source as MenuItem;
+ if (item.DataContext != null)
+ {
+ ZeroTierNetwork network = item.DataContext as ZeroTierNetwork;
+ if (item.IsChecked)
+ {
+ APIHandler.Instance.LeaveNetwork(network.NetworkId);
+ }
+ else
+ {
+ APIHandler.Instance.JoinNetwork(network.NetworkId, network.AllowManaged, network.AllowGlobal, network.AllowDefault);
+ }
+ }
+ }
+ }
}
}
diff --git a/windows/WinUI/ZeroTierNetwork.cs b/windows/WinUI/ZeroTierNetwork.cs
index 2bcb76e2e..ecae0256c 100644
--- a/windows/WinUI/ZeroTierNetwork.cs
+++ b/windows/WinUI/ZeroTierNetwork.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
@@ -9,8 +11,27 @@ using Newtonsoft.Json;
namespace WinUI
{
[Serializable]
- public class ZeroTierNetwork : ISerializable, IEquatable, IComparable
+ public class ZeroTierNetwork : ISerializable, IEquatable, IComparable, INotifyPropertyChanged
{
+ private string networkId;
+ private string macAddress;
+ private string networkName;
+ private string networkStatus;
+ private string networkType;
+ private Int32 mtu;
+ private bool dhcp;
+ private bool bridge;
+ private bool broadcastEnabled;
+ private Int32 portError;
+ private Int32 netconfRevision;
+ private string[] assignedAddresses;
+ private NetworkRoute[] routes;
+ private string deviceName;
+ private bool allowManaged;
+ private bool allowGlobal;
+ private bool allowDefault;
+ private bool isConnected;
+
protected ZeroTierNetwork(SerializationInfo info, StreamingContext ctx)
{
try
@@ -37,6 +58,8 @@ namespace WinUI
IsConnected = false;
}
+ public event PropertyChangedEventHandler PropertyChanged;
+
public virtual void GetObjectData(SerializationInfo info, StreamingContext ctx)
{
info.AddValue("nwid", NetworkId);
@@ -58,59 +81,351 @@ namespace WinUI
info.AddValue("allowDefault", AllowDefault);
}
+ public void UpdateNetwork(ZeroTierNetwork network)
+ {
+ if (network == null)
+ return;
+
+ if (!NetworkId.Equals(network.NetworkId))
+ {
+ NetworkId = network.NetworkId;
+ }
+
+ if (!MacAddress.Equals(network.MacAddress))
+ {
+ MacAddress = network.MacAddress;
+ }
+
+ if (!NetworkName.Equals(network.NetworkName))
+ {
+ NetworkName = network.NetworkName;
+ }
+
+ if (!NetworkStatus.Equals(network.NetworkStatus))
+ {
+ NetworkStatus = network.NetworkStatus;
+ }
+
+ if (!NetworkType.Equals(network.NetworkType))
+ {
+ NetworkType = network.NetworkType;
+ }
+
+ if (MTU != network.MTU)
+ {
+ MTU = network.MTU;
+ }
+
+ if (DHCP != network.DHCP)
+ {
+ DHCP = network.DHCP;
+ }
+
+ if (Bridge != network.Bridge)
+ {
+ Bridge = network.Bridge;
+ }
+
+ if (BroadcastEnabled != network.BroadcastEnabled)
+ {
+ BroadcastEnabled = network.BroadcastEnabled;
+ }
+
+ if (PortError != network.PortError)
+ {
+ PortError = network.PortError;
+ }
+
+ if (NetconfRevision != network.NetconfRevision)
+ {
+ NetconfRevision = network.NetconfRevision;
+ }
+
+ AssignedAddresses = network.AssignedAddresses;
+
+ Routes = network.Routes;
+
+ if (!DeviceName.Equals(network.DeviceName))
+ {
+ DeviceName = network.DeviceName;
+ }
+
+ if (AllowManaged != network.AllowManaged)
+ {
+ AllowManaged = network.AllowManaged;
+ }
+
+ if (AllowGlobal != network.AllowGlobal)
+ {
+ AllowGlobal = network.AllowGlobal;
+ }
+
+ if (AllowDefault != network.AllowDefault)
+ {
+ AllowDefault = network.AllowDefault;
+ }
+
+ if (IsConnected != network.IsConnected)
+ {
+ IsConnected = network.IsConnected;
+ }
+ }
+
+ protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
[JsonProperty("nwid")]
- public string NetworkId { get; set; }
+ public string NetworkId {
+ get
+ {
+ return networkId;
+ }
+ set
+ {
+ networkId = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("mac")]
- public string MacAddress { get; set; }
+ public string MacAddress
+ {
+ get
+ {
+ return macAddress;
+ }
+ set
+ {
+ macAddress = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("name")]
- public string NetworkName { get; set; }
+ public string NetworkName
+ {
+ get
+ {
+ return networkName;
+ }
+ set
+ {
+ networkName = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("status")]
- public string NetworkStatus { get; set; }
+ public string NetworkStatus
+ {
+ get
+ {
+ return networkStatus;
+ }
+ set
+ {
+ networkStatus = value;
+ NotifyPropertyChanged();
+ }
+
+ }
[JsonProperty("type")]
- public string NetworkType { get; set; }
+ public string NetworkType
+ {
+ get
+ {
+ return networkType;
+ }
+ set
+ {
+ networkType = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("mtu")]
- public int MTU { get; set; }
+ public int MTU
+ {
+ get
+ {
+ return mtu;
+ }
+ set
+ {
+ mtu = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("dhcp")]
- public bool DHCP { get; set; }
+ public bool DHCP
+ {
+ get
+ {
+ return dhcp;
+ }
+ set
+ {
+ dhcp = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("bridge")]
- public bool Bridge { get; set ; }
+ public bool Bridge
+ {
+ get
+ {
+ return bridge;
+ }
+ set
+ {
+ bridge = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("broadcastEnabled")]
- public bool BroadcastEnabled { get ; set; }
+ public bool BroadcastEnabled
+ {
+ get
+ {
+ return broadcastEnabled;
+ }
+ set
+ {
+ broadcastEnabled = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("portError")]
- public int PortError { get; set; }
+ public int PortError
+ {
+ get
+ {
+ return portError;
+ }
+ set
+ {
+ portError = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("netconfRevision")]
- public int NetconfRevision { get; set; }
+ public int NetconfRevision
+ {
+ get
+ {
+ return netconfRevision;
+ }
+ set
+ {
+ netconfRevision = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("assignedAddresses")]
- public string[] AssignedAddresses { get; set; }
+ public string[] AssignedAddresses
+ {
+ get
+ {
+ return assignedAddresses;
+ }
+ set
+ {
+ assignedAddresses = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("routes")]
- public NetworkRoute[] Routes { get; set; }
+ public NetworkRoute[] Routes
+ {
+ get
+ {
+ return routes;
+ }
+ set
+ {
+ routes = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("portDeviceName")]
- public string DeviceName { get; set; }
+ public string DeviceName
+ {
+ get
+ {
+ return deviceName;
+ }
+ set
+ {
+ deviceName = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("allowManaged")]
- public bool AllowManaged { get; set; }
+ public bool AllowManaged
+ {
+ get
+ {
+ return allowManaged;
+ }
+ set
+ {
+ allowManaged = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("allowGlobal")]
- public bool AllowGlobal { get; set; }
+ public bool AllowGlobal
+ {
+ get
+ {
+ return allowGlobal;
+ }
+ set
+ {
+ allowGlobal = value;
+ NotifyPropertyChanged();
+ }
+ }
[JsonProperty("allowDefault")]
- public bool AllowDefault { get; set; }
+ public bool AllowDefault
+ {
+ get
+ {
+ return allowDefault;
+ }
+ set
+ {
+ allowDefault = value;
+ NotifyPropertyChanged();
+ }
+ }
- public bool IsConnected { get; set; } = false;
+ public bool IsConnected
+ {
+ get
+ {
+ return isConnected;
+ }
+ set
+ {
+ isConnected = value;
+ NotifyPropertyChanged();
+ }
+ }
public String Title
{