diff options
Diffstat (limited to 'windows/WinUI/Views')
-rw-r--r-- | windows/WinUI/Views/AboutView.xaml | 12 | ||||
-rw-r--r-- | windows/WinUI/Views/AboutView.xaml.cs | 27 | ||||
-rw-r--r-- | windows/WinUI/Views/JoinNetworkView.xaml | 12 | ||||
-rw-r--r-- | windows/WinUI/Views/JoinNetworkView.xaml.cs | 27 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworkInfoView.xaml | 82 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworkInfoView.xaml.cs | 131 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworkListView.xaml | 134 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworkListView.xaml.cs | 143 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworksPage.xaml | 13 | ||||
-rw-r--r-- | windows/WinUI/Views/NetworksPage.xaml.cs | 99 | ||||
-rw-r--r-- | windows/WinUI/Views/PeersPage.xaml | 26 | ||||
-rw-r--r-- | windows/WinUI/Views/PeersPage.xaml.cs | 54 | ||||
-rw-r--r-- | windows/WinUI/Views/ToolbarItem.xaml | 74 | ||||
-rw-r--r-- | windows/WinUI/Views/ToolbarItem.xaml.cs | 158 |
14 files changed, 992 insertions, 0 deletions
diff --git a/windows/WinUI/Views/AboutView.xaml b/windows/WinUI/Views/AboutView.xaml new file mode 100644 index 00000000..b32ac327 --- /dev/null +++ b/windows/WinUI/Views/AboutView.xaml @@ -0,0 +1,12 @@ +<Window x:Class="WinUI.AboutView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WinUI" + mc:Ignorable="d" + Title="AboutView" Height="300" Width="300"> + <Grid> + + </Grid> +</Window> diff --git a/windows/WinUI/Views/AboutView.xaml.cs b/windows/WinUI/Views/AboutView.xaml.cs new file mode 100644 index 00000000..38c6134a --- /dev/null +++ b/windows/WinUI/Views/AboutView.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for AboutView.xaml + /// </summary> + public partial class AboutView : Window + { + public AboutView() + { + InitializeComponent(); + } + } +} diff --git a/windows/WinUI/Views/JoinNetworkView.xaml b/windows/WinUI/Views/JoinNetworkView.xaml new file mode 100644 index 00000000..b359fcd8 --- /dev/null +++ b/windows/WinUI/Views/JoinNetworkView.xaml @@ -0,0 +1,12 @@ +<Window x:Class="WinUI.JoinNetworkView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WinUI" + mc:Ignorable="d" + Title="JoinNetworkView" Height="300" Width="300"> + <Grid> + + </Grid> +</Window> diff --git a/windows/WinUI/Views/JoinNetworkView.xaml.cs b/windows/WinUI/Views/JoinNetworkView.xaml.cs new file mode 100644 index 00000000..eca0647e --- /dev/null +++ b/windows/WinUI/Views/JoinNetworkView.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for JoinNetworkView.xaml + /// </summary> + public partial class JoinNetworkView : Window + { + public JoinNetworkView() + { + InitializeComponent(); + } + } +} diff --git a/windows/WinUI/Views/NetworkInfoView.xaml b/windows/WinUI/Views/NetworkInfoView.xaml new file mode 100644 index 00000000..b3e8cae0 --- /dev/null +++ b/windows/WinUI/Views/NetworkInfoView.xaml @@ -0,0 +1,82 @@ +<UserControl Background="LightGray" x:Class="WinUI.NetworkInfoView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + > + + <Border Background="GhostWhite" BorderBrush="Gainsboro" BorderThickness="1" CornerRadius="8,8,8,8"> + <Grid Background="GhostWhite" Margin="10,10,10,10"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="auto"/> + <ColumnDefinition Width="10"/> + <ColumnDefinition Width="*"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + <RowDefinition Height="auto"/> + </Grid.RowDefinitions> + + <Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="auto"/> + <ColumnDefinition Width="*"/> + </Grid.ColumnDefinitions> + + <TextBox x:Name="networkId" Text="8056c2e21c000001" HorizontalAlignment="Left" Grid.Column="0" Foreground="#FF91A2A3" FontFamily="Lucida Console" BorderThickness="0" IsReadOnly="true" Background="Transparent"/> + <TextBox x:Name="networkName" Text="earth.zerotier.net" HorizontalAlignment="Right" Grid.Column="1" Foreground="#FF000000" BorderThickness="0" IsReadOnly="true" Background="Transparent"/> + </Grid> + + <Separator Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3"/> + + <TextBlock TextWrapping="Wrap" Text="Status" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="2" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Type" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="3" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="MAC" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="4" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="MTU" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="5" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Broadcast" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="6" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Bridging" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="7" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Device" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="8" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Managed IPs" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="9" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Allow Global IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="10" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Allow Managed IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="11" Foreground="#FF000000"/> + <TextBlock TextWrapping="Wrap" Text="Allow Default Route" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="12" Foreground="#FF000000"/> + + <Rectangle Grid.Column="2" Grid.Row="2" Grid.RowSpan="11" Fill="#FFEEEEEE"/> + + <TextBlock x:Name="networkStatus" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Text="OK" TextAlignment="Right" Grid.Column="2" Grid.Row="2" Foreground="#FF000000"/> + <TextBlock x:Name="networkType" FontFamily="Lucida Console" TextWrapping="Wrap" Text="PUBLIC" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="3" Foreground="#FF000000"/> + <TextBlock x:Name="macAddress" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="4" Foreground="#FF000000"><Span><Run Text="02:83:4a:1e:4b:3a"/></Span></TextBlock> + <TextBlock x:Name="mtu" FontFamily="Lucida Console" TextWrapping="Wrap" Text="2800" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="5" Foreground="#FF000000"/> + <TextBlock x:Name="broadcastEnabled" FontFamily="Lucida Console" TextWrapping="Wrap" Text="ENABLED" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="6" Foreground="#FF000000"/> + <TextBlock x:Name="bridgingEnabled" FontFamily="Lucida Console" TextWrapping="Wrap" Text="DISABLED" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="7" Background="#FFEEEEEE" Foreground="#FF000000"/> + <TextBlock x:Name="deviceName" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="8" Foreground="#FF000000"><Span><Run Text="ethernet_32771"/></Span></TextBlock> + <TextBox x:Name="managedIps" TextWrapping="Wrap" FontFamily="Lucida Console" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="2" Grid.Row="9" Foreground="#FF000000" IsReadOnly="True" BorderThickness="0" Background="#FFEEEEEE" Text="28.2.169.248/7
fd80:56c2:e21c:0000:0199:9383:4a02:a9f8/88"/> + <CheckBox x:Name="allowGlobal" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="10" /> + <CheckBox x:Name="allowManaged" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="11" /> + <CheckBox x:Name="allowDefault" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="12" /> + + <Separator Grid.Column="0" Grid.Row="13" Grid.ColumnSpan="3"/> + + <Grid Grid.Column="0" Grid.Row="14" Grid.ColumnSpan="3" Background="GhostWhite"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + </Grid.ColumnDefinitions> + <Button x:Name="leaveButton" Content="Leave" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75" Background="#FFFFB354" Click="leaveButton_Click"/> + </Grid> + </Grid> + </Border> +</UserControl> diff --git a/windows/WinUI/Views/NetworkInfoView.xaml.cs b/windows/WinUI/Views/NetworkInfoView.xaml.cs new file mode 100644 index 00000000..ed4cc628 --- /dev/null +++ b/windows/WinUI/Views/NetworkInfoView.xaml.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for NetworkInfoView.xaml + /// </summary> + public partial class NetworkInfoView : UserControl + { + public ZeroTierNetwork network; + + public NetworkInfoView(ZeroTierNetwork network) + { + InitializeComponent(); + + 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() + { + + 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"); + + if (this.deviceName.Text != network.DeviceName) + this.deviceName.Text = network.DeviceName; + + string iplist = ""; + for (int i = 0; i < network.AssignedAddresses.Length; ++i) + { + iplist += network.AssignedAddresses[i]; + if (i < (network.AssignedAddresses.Length - 1)) + iplist += "\n"; + } + + if (this.managedIps.Text != iplist) + this.managedIps.Text = iplist; + + this.allowDefault.IsChecked = network.AllowDefault; + this.allowGlobal.IsChecked = network.AllowGlobal; + this.allowManaged.IsChecked = network.AllowManaged; + } + + public bool HasNetwork(ZeroTierNetwork network) + { + if (this.network.NetworkId.Equals(network.NetworkId)) + return true; + + return false; + } + + public void SetNetworkInfo(ZeroTierNetwork network) + { + this.network = network; + + UpdateNetworkData(); + } + + private void leaveButton_Click(object sender, RoutedEventArgs e) + { + APIHandler.Instance.LeaveNetwork(network.NetworkId); + } + + private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + APIHandler.Instance.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } + + private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + APIHandler.Instance.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } + + private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + APIHandler.Instance.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } + } +} diff --git a/windows/WinUI/Views/NetworkListView.xaml b/windows/WinUI/Views/NetworkListView.xaml new file mode 100644 index 00000000..a1e74531 --- /dev/null +++ b/windows/WinUI/Views/NetworkListView.xaml @@ -0,0 +1,134 @@ +<Window + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WinUI" + mc:Ignorable="d" x:Class="WinUI.NetworkListView" + Title="ZeroTier One" Height="500" Width="500" Icon="ZeroTierIcon.ico"> + + <Window.Resources> + <SolidColorBrush x:Key="GreenBrush" Color="#ff91a2a3"/> + + <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" /> + + <SolidColorBrush x:Key="GreenDisabledBrush" Color="#FF234447" /> + + <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" /> + + <SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" /> + + <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" /> + + <Style TargetType="{x:Type DataGrid}"> + <Setter Property="Background" Value="#FFF" /> + <Setter Property="AlternationCount" Value="2" /> + </Style> + + <Style TargetType="{x:Type DataGridRow}"> + <Style.Triggers> + <Trigger Property="ItemsControl.AlternationIndex" Value="0"> + <Setter Property="Background" Value="#EEE"></Setter> + </Trigger> + <Trigger Property="ItemsControl.AlternationIndex" Value="1"> + <Setter Property="Background" Value="#FFF"></Setter> + </Trigger> + </Style.Triggers> + </Style> + + <Style TargetType="{x:Type TabItem}"> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type TabItem}"> + <Grid> + <Border + Name="Border" + Margin="0,0,-4,0" + Background="{StaticResource GreenBrush}" + BorderBrush="{StaticResource SolidBorderBrush}" + BorderThickness="1,1,1,1" + CornerRadius="2,12,0,0" > + <ContentPresenter x:Name="ContentSite" + VerticalAlignment="Center" + HorizontalAlignment="Center" + ContentSource="Header" + Margin="12,2,12,2" + RecognizesAccessKey="True"/> + </Border> + </Grid> + <ControlTemplate.Triggers> + <Trigger Property="IsSelected" Value="True"> + <Setter Property="Panel.ZIndex" Value="100" /> + <Setter TargetName="Border" Property="Background" Value="{StaticResource GreenDisabledBrush}" /> + <Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" /> + </Trigger> + <Trigger Property="IsEnabled" Value="False"> + <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" /> + <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" /> + <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" /> + </Trigger> + </ControlTemplate.Triggers> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Window.Resources> + + <DockPanel> + <StatusBar DockPanel.Dock="Bottom" Height="26" Background="#FF234447" Margin="0"> + <StatusBar.ItemsPanel> + <ItemsPanelTemplate> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition Width="*"/> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition Width="Auto"/> + </Grid.ColumnDefinitions> + </Grid> + </ItemsPanelTemplate> + </StatusBar.ItemsPanel> + <StatusBarItem Grid.Column="0" x:Name="networkId_placeholder"> + <TextBox x:Name="networkId" Text="deadbeef00" HorizontalAlignment="Left" Grid.Column="0" Foreground="White" FontFamily="Lucida Console" BorderThickness="0" IsReadOnly="true" Background="Transparent"/> + </StatusBarItem> + <StatusBarItem Grid.Column="1" x:Name="onlineStatus" Content="ONLINE" Foreground="White" FontFamily="Lucida Console"/> + <StatusBarItem Grid.Column="2" x:Name="versionString" Content="1.0.5" Foreground="White" FontFamily="Lucida Console"/> + <StatusBarItem Grid.Column="3" x:Name="blank" Content="" Height="43" Foreground="White"/> + <StatusBarItem Grid.Column="4"> + <TextBox x:Name="joinNetworkID" TextWrapping="Wrap" Width="140" HorizontalAlignment="Right" ToolTip="Enter Network ID" PreviewTextInput="OnNetworkEntered" MaxLength="16" FontFamily="Lucida Console" FontSize="12" BorderThickness="1"/> + </StatusBarItem> + <StatusBarItem Grid.Column="5" x:Name="statusBarButton" Foreground="White" RenderTransformOrigin="0.789,0.442"> + <Button x:Name="joinButton" Content="Join" Background="#FFFFB354" Width="76" Click="joinButton_Click"/> + </StatusBarItem> + </StatusBar> + <!--<TabControl Margin="0,0,0,0"> + <TabItem x:Name="Networks" Header="Networks" Foreground="White" IsSelected="True" IsManipulationEnabled="True">--> + <Grid Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <local:NetworksPage x:Name="networksPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Margin="0,0,0,0"/> + </Grid> + <!--</TabItem>--> + <!--<TabItem x:Name="Peers" Header="Peers" Foreground="White"> + <Grid Background="#FFE5E5E5" HorizontalAlignment="Left" VerticalAlignment="Top"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <local:PeersPage x:Name="peersPage" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.Row="0"/> + </Grid> + </TabItem>--> + <!--</TabControl>--> + </DockPanel> +</Window> diff --git a/windows/WinUI/Views/NetworkListView.xaml.cs b/windows/WinUI/Views/NetworkListView.xaml.cs new file mode 100644 index 00000000..c89d4bcc --- /dev/null +++ b/windows/WinUI/Views/NetworkListView.xaml.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Timers; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for MainWindow.xaml + /// </summary> + public partial class NetworkListView : Window + { + Regex charRegex = new Regex("[0-9a-fxA-FX]"); + Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); + + Timer timer = new Timer(); + + bool connected = false; + + public NetworkListView() + { + InitializeComponent(); + + APIHandler.Instance.GetStatus(updateStatus); + + if (!connected) + { + MessageBox.Show("Unable to connect to ZerOTier Service"); + return; + } + + APIHandler.Instance.GetNetworks(updateNetworks); + + DataObject.AddPastingHandler(joinNetworkID, OnPaste); + + timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); + timer.Interval = 2000; + timer.Enabled = true; + + + } + + private void updateStatus(ZeroTierStatus status) + { + if (status != null) + { + connected = true; + + networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.networkId.Text = status.Address; + })); + versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.versionString.Content = status.Version; + })); + onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE"); + })); + } + else + { + connected = false; + + networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.networkId.Text = ""; + })); + versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.versionString.Content = "0"; + })); + onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + this.onlineStatus.Content = "OFFLINE"; + })); + } + } + + private void updateNetworks(List<ZeroTierNetwork> networks) + { + if (networks != null) + { + networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + networksPage.setNetworks(networks); + })); + } + } + + private void OnUpdateTimer(object source, ElapsedEventArgs e) + { + APIHandler.Instance.GetStatus(updateStatus); + APIHandler.Instance.GetNetworks(updateNetworks); + } + + private void joinButton_Click(object sender, RoutedEventArgs e) + { + if (joinNetworkID.Text.Length < 16) + { + MessageBox.Show("Invalid Network ID"); + } + else + { + APIHandler.Instance.JoinNetwork(joinNetworkID.Text); + } + } + + private void OnNetworkEntered(object sender, TextCompositionEventArgs e) + { + e.Handled = !charRegex.IsMatch(e.Text); + } + + private void OnPaste(object sender, DataObjectPastingEventArgs e) + { + var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true); + if (!isText) return; + + var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string; + + if (!wholeStringRegex.IsMatch(text)) + { + e.CancelCommand(); + } + } + } +} diff --git a/windows/WinUI/Views/NetworksPage.xaml b/windows/WinUI/Views/NetworksPage.xaml new file mode 100644 index 00000000..6f95bc05 --- /dev/null +++ b/windows/WinUI/Views/NetworksPage.xaml @@ -0,0 +1,13 @@ +<UserControl x:Class="WinUI.NetworksPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300"> + <ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> + <UniformGrid x:Name="wrapPanel" Background="#FFDDDDDD" HorizontalAlignment="Stretch" VerticalAlignment="Top" Columns="1"> + + </UniformGrid> + </ScrollViewer> +</UserControl> diff --git a/windows/WinUI/Views/NetworksPage.xaml.cs b/windows/WinUI/Views/NetworksPage.xaml.cs new file mode 100644 index 00000000..39a2fefc --- /dev/null +++ b/windows/WinUI/Views/NetworksPage.xaml.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for NetworksPage.xaml + /// </summary> + public partial class NetworksPage : UserControl + { + public NetworksPage() + { + InitializeComponent(); + } + + public void setNetworks(List<ZeroTierNetwork> networks) + { + if (networks == null) + { + this.wrapPanel.Children.Clear(); + return; + } + + foreach (ZeroTierNetwork network in networks) + { + NetworkInfoView view = ChildWithNetwork(network); + if (view != null) + { + view.SetNetworkInfo(network); + } + else + { + wrapPanel.Children.Add( + new NetworkInfoView( + 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; + } + } +} diff --git a/windows/WinUI/Views/PeersPage.xaml b/windows/WinUI/Views/PeersPage.xaml new file mode 100644 index 00000000..57b11edf --- /dev/null +++ b/windows/WinUI/Views/PeersPage.xaml @@ -0,0 +1,26 @@ +<UserControl x:Class="WinUI.PeersPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300" Background="White" Foreground="Black"> + + <DataGrid x:Name="dataGrid" GridLinesVisibility="None" AutoGenerateColumns="False" CanUserResizeColumns="True" Margin="0,0,0,0" CanUserReorderColumns="False" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto" CanUserSortColumns="False"> + <DataGrid.CellStyle> + <Style TargetType="DataGridCell"> + <Setter Property="BorderThickness" Value="0"/> + <Setter Property="FocusVisualStyle" Value="{x:Null}"/> + </Style> + </DataGrid.CellStyle> + <DataGrid.Columns> + <DataGridTextColumn Header="Address" Binding="{Binding Address}"/> + <DataGridTextColumn Header="Version" Binding="{Binding VersionString}"/> + <DataGridTextColumn Header="Latency" Binding="{Binding Latency}"/> + <DataGridTextColumn Header="Data Paths" Binding="{Binding DataPaths}"/> + <DataGridTextColumn Header="Last Unicast" Binding="{Binding LastUnicastFrame}"/> + <DataGridTextColumn Header="Last Multicast" Binding="{Binding LastMulticastFrame}"/> + <DataGridTextColumn Width="*" Header="Role" Binding="{Binding Role}"/> + </DataGrid.Columns> + </DataGrid> +</UserControl> diff --git a/windows/WinUI/Views/PeersPage.xaml.cs b/windows/WinUI/Views/PeersPage.xaml.cs new file mode 100644 index 00000000..fac22a49 --- /dev/null +++ b/windows/WinUI/Views/PeersPage.xaml.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for PeersPage.xaml + /// </summary> + public partial class PeersPage : UserControl + { + private List<ZeroTierPeer> peersList = new List<ZeroTierPeer>(); + + public PeersPage() + { + InitializeComponent(); + + dataGrid.ItemsSource = peersList; + } + + public void SetPeers(List<ZeroTierPeer> list) + { + if (list == null) + return; + + + foreach(ZeroTierPeer p in list) + { + ZeroTierPeer curPeer = peersList.Find(peer => peer.Equals(p)); + if (curPeer == null) + { + peersList.Add(p); + } + else + { + curPeer.Update(p); + } + } + + dataGrid.Items.Refresh(); + } + } +} diff --git a/windows/WinUI/Views/ToolbarItem.xaml b/windows/WinUI/Views/ToolbarItem.xaml new file mode 100644 index 00000000..bbc17649 --- /dev/null +++ b/windows/WinUI/Views/ToolbarItem.xaml @@ -0,0 +1,74 @@ +<Window x:Class="WinUI.ToolbarItem" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WinUI" + xmlns:tb="http://www.hardcodet.net/taskbar" + xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" + mc:Ignorable="d" + Height="300" Width="300" Visibility="Hidden" Name="Toolbar"> + + <Window.Resources> + <CollectionViewSource Source="{Binding ElementName=Toolbar, Path=NetworkCollection}" x:Key="KnownNetworks"> + <CollectionViewSource.SortDescriptions> + <scm:SortDescription PropertyName="Header" Direction="Ascending"/> + </CollectionViewSource.SortDescriptions> + </CollectionViewSource> + </Window.Resources> + + <Grid> + <tb:TaskbarIcon x:Name="MyNotifyIcon" + IconSource="ZeroTierIcon.ico" + ToolTipText="ZeroTier One" + TrayContextMenuOpen="ToolbarItem_TrayContextMenuOpen" + PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen"> + <tb:TaskbarIcon.ContextMenu> + <ContextMenu> + <ContextMenu.ItemsSource> + <CompositeCollection> + <MenuItem Header="Node ID: abeb9f9bc5" + Click="ToolbarItem_NodeIDClicked" + x:Name="nodeIdMenuItem"/> + <Separator/> + <MenuItem Header="Join Network..." + Click="ToolbarItem_JoinNetworkClicked"/> + <MenuItem Header="Show Networks..." + Click="ToolbarItem_ShowNetworksClicked"/> + <Separator/> + + <CollectionContainer Collection="{Binding Source={StaticResource KnownNetworks}}"> + + </CollectionContainer> + + <Separator/> + <MenuItem Header="About..."/> + <MenuItem Header="Preferences..."/> + <Separator/> + <MenuItem Header="Quit"/> + + </CompositeCollection> + </ContextMenu.ItemsSource> + + <!--<MenuItem Header="Networks"> + <MenuItem.ItemsSource> + <CompositeCollection> + <CollectionContainer Collection="{Binding Source={StaticResource KnownNetworks}}"/> + </CompositeCollection> + </MenuItem.ItemsSource> + <MenuItem.ItemContainerStyle> + <Style> + <Setter Property="MenuItem.Header" Value="{Binding Title}"/> + --><!-- <Setter Property="MenuItem.IsCheckable" Value="True"/> --><!-- + <Setter Property="MenuItem.IsChecked" Value="{Binding IsConnected}"/> + <EventSetter Event="MenuItem.Click" Handler="ToolbarItem_NetworkClicked"/> + </Style> + </MenuItem.ItemContainerStyle> + </MenuItem>--> + + </ContextMenu> + </tb:TaskbarIcon.ContextMenu> + + </tb:TaskbarIcon> + </Grid> +</Window> diff --git a/windows/WinUI/Views/ToolbarItem.xaml.cs b/windows/WinUI/Views/ToolbarItem.xaml.cs new file mode 100644 index 00000000..15aeb24b --- /dev/null +++ b/windows/WinUI/Views/ToolbarItem.xaml.cs @@ -0,0 +1,158 @@ +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; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Text.RegularExpressions; +using System.Timers; +using System.Windows.Threading; +using System.IO; +using System.Diagnostics; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for ToolbarItem.xaml + /// </summary> + public partial class ToolbarItem : Window, INotifyPropertyChanged + { + private APIHandler handler = APIHandler.Instance; + + private NetworkListView netListView = null; + + private NetworkMonitor mon = NetworkMonitor.Instance; + + private ObservableCollection<MenuItem> _networkCollection = new ObservableCollection<MenuItem>(); + + public ObservableCollection<MenuItem> NetworkCollection + { + get { return _networkCollection; } + set { _networkCollection = value; } + } + + public ToolbarItem() + { + InitializeComponent(); + + mon.SubscribeNetworkUpdates(updateNetworks); + mon.SubscribeStatusUpdates(updateStatus); + } + + ~ToolbarItem() + { + mon.UnsubscribeNetworkUpdates(updateNetworks); + mon.UnsubscribeStatusUpdates(updateStatus); + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void updateNetworks(List<ZeroTierNetwork> networks) + { + if (networks != null) + { + this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + NetworkCollection.Clear(); + foreach (ZeroTierNetwork n in networks) + { + MenuItem item = new MenuItem(); + item.Header = n.Title; + item.DataContext = n; + item.IsChecked = n.IsConnected; + item.Click += ToolbarItem_NetworkClicked; + + NetworkCollection.Add(item); + } + })); + } + } + + private void updateStatus(ZeroTierStatus status) + { + if (status != null) + { + Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + nodeIdMenuItem.Header = "Node ID: " + status.Address; + nodeIdMenuItem.IsEnabled = true; + })); + } + } + + private void ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("TrayContextMenuOpen"); + } + + private void ToolbarItem_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("PreviewTrayContextMenuOpen"); + } + + private void ToolbarItem_NodeIDClicked(object sender, System.Windows.RoutedEventArgs e) + { + + } + + private void ToolbarItem_ShowNetworksClicked(object sender, System.Windows.RoutedEventArgs e) + { + if (netListView == null) + { + netListView = new WinUI.NetworkListView(); + netListView.Closed += ShowNetworksClosed; + netListView.Show(); + } + } + + private void ShowNetworksClosed(object sender, System.EventArgs e) + { + netListView = null; + } + + private void ToolbarItem_JoinNetworkClicked(object sender, System.EventArgs e) + { + + } + + private void JoinNetworkClosed(object sender, System.EventArgs e) + { + + } + + 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); + } + } + } + } + } +} |