diff options
Diffstat (limited to 'windows')
19 files changed, 236 insertions, 988 deletions
diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 015415c3..6a944f0f 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -12,7 +12,7 @@ using System.Windows.Threading; namespace WinUI { - + public class APIHandler { @@ -58,19 +58,19 @@ namespace WinUI String authToken = ""; Int32 port = 9993; - if (resetToken) - { - instance = null; - if (File.Exists(localZtDir + "\\authtoken.secret")) - { - File.Delete(localZtDir + "\\authtoken.secret"); - } + if (resetToken) + { + instance = null; + if (File.Exists(localZtDir + "\\authtoken.secret")) + { + File.Delete(localZtDir + "\\authtoken.secret"); + } - if (File.Exists(localZtDir + "\\zerotier-one.port")) - { - File.Delete(localZtDir + "\\zerotier-one.port"); - } - } + if (File.Exists(localZtDir + "\\zerotier-one.port")) + { + File.Delete(localZtDir + "\\zerotier-one.port"); + } + } if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) { @@ -78,7 +78,7 @@ namespace WinUI String curPath = System.Reflection.Assembly.GetEntryAssembly().Location; int index = curPath.LastIndexOf("\\"); curPath = curPath.Substring(0, index); - ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", "\""+globalZtDir+"\"" + " " + "\""+localZtDir+"\""); + ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", "\"" + globalZtDir + "\"" + " " + "\"" + localZtDir + "\""); startInfo.Verb = "runas"; @@ -148,7 +148,7 @@ namespace WinUI this.authtoken = authtoken; } - + public void GetStatus(StatusCallback cb) { @@ -162,33 +162,33 @@ namespace WinUI try { var httpResponse = (HttpWebResponse)request.GetResponse(); - if (httpResponse.StatusCode == HttpStatusCode.OK) - { - using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) - { - var responseText = streamReader.ReadToEnd(); + if (httpResponse.StatusCode == HttpStatusCode.OK) + { + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); - ZeroTierStatus status = null; - try - { - status = JsonConvert.DeserializeObject<ZeroTierStatus>(responseText); + ZeroTierStatus status = null; + try + { + status = JsonConvert.DeserializeObject<ZeroTierStatus>(responseText); if (ZeroTierAddress != status.Address) { ZeroTierAddress = status.Address; } - } - catch (JsonReaderException e) - { - Console.WriteLine(e.ToString()); - } - cb(status); - } - } - else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } + } + catch (JsonReaderException e) + { + Console.WriteLine(e.ToString()); + } + cb(status); + } + } + else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } } catch (System.Net.Sockets.SocketException) { @@ -196,19 +196,19 @@ namespace WinUI } catch (System.Net.WebException e) { - HttpWebResponse res = (HttpWebResponse)e.Response; - if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - else - { - cb(null); - } + HttpWebResponse res = (HttpWebResponse)e.Response; + if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + else + { + cb(null); + } } } - + public void GetNetworks(NetworkListCallback cb) { @@ -226,33 +226,33 @@ namespace WinUI { var httpResponse = (HttpWebResponse)request.GetResponse(); - if (httpResponse.StatusCode == HttpStatusCode.OK) - { - using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) - { - var responseText = streamReader.ReadToEnd(); - - List<ZeroTierNetwork> networkList = null; - try - { - networkList = JsonConvert.DeserializeObject<List<ZeroTierNetwork>>(responseText); - foreach (ZeroTierNetwork n in networkList) - { - // all networks received via JSON are connected by definition - n.IsConnected = true; - } - } - catch (JsonReaderException e) - { - Console.WriteLine(e.ToString()); - } - cb(networkList); - } - } - else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } + if (httpResponse.StatusCode == HttpStatusCode.OK) + { + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + + List<ZeroTierNetwork> networkList = null; + try + { + networkList = JsonConvert.DeserializeObject<List<ZeroTierNetwork>>(responseText); + foreach (ZeroTierNetwork n in networkList) + { + // all networks received via JSON are connected by definition + n.IsConnected = true; + } + } + catch (JsonReaderException e) + { + Console.WriteLine(e.ToString()); + } + cb(networkList); + } + } + else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } } catch (System.Net.Sockets.SocketException) { @@ -260,137 +260,137 @@ namespace WinUI } catch (System.Net.WebException e) { - HttpWebResponse res = (HttpWebResponse)e.Response; - if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - else - { - cb(null); - } + HttpWebResponse res = (HttpWebResponse)e.Response; + if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + else + { + cb(null); + } } } public void JoinNetwork(Dispatcher d, string nwid, bool allowManaged = true, bool allowGlobal = false, bool allowDefault = false) { - Task.Factory.StartNew(() => - { - var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; - if (request == null) - { - return; - } - - request.Method = "POST"; - request.ContentType = "applicaiton/json"; - request.Timeout = 30000; - try - { - using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream())) - { - string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," + - "\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," + - "\"allowDefault\":" + (allowDefault ? "true" : "false") + "}"; - streamWriter.Write(json); - streamWriter.Flush(); - streamWriter.Close(); - } - } - catch (System.Net.WebException) - { - d.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); - })); - return; - } - - try - { - var httpResponse = (HttpWebResponse)request.GetResponse(); - - if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - else if (httpResponse.StatusCode != HttpStatusCode.OK) - { - Console.WriteLine("Error sending join network message"); - } - } - catch (System.Net.Sockets.SocketException) - { - d.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); - })); - } - catch (System.Net.WebException e) - { - HttpWebResponse res = (HttpWebResponse)e.Response; - if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - d.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); - })); - } - }); + Task.Factory.StartNew(() => + { + var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; + if (request == null) + { + return; + } + + request.Method = "POST"; + request.ContentType = "applicaiton/json"; + request.Timeout = 30000; + try + { + using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream())) + { + string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," + + "\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," + + "\"allowDefault\":" + (allowDefault ? "true" : "false") + "}"; + streamWriter.Write(json); + streamWriter.Flush(); + streamWriter.Close(); + } + } + catch (System.Net.WebException) + { + d.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); + })); + return; + } + + try + { + var httpResponse = (HttpWebResponse)request.GetResponse(); + + if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + else if (httpResponse.StatusCode != HttpStatusCode.OK) + { + Console.WriteLine("Error sending join network message"); + } + } + catch (System.Net.Sockets.SocketException) + { + d.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); + })); + } + catch (System.Net.WebException e) + { + HttpWebResponse res = (HttpWebResponse)e.Response; + if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + d.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service."); + })); + } + }); } public void LeaveNetwork(Dispatcher d, string nwid) { - Task.Factory.StartNew(() => - { - var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; - if (request == null) - { - return; - } - - request.Method = "DELETE"; - request.Timeout = 30000; - - try - { - var httpResponse = (HttpWebResponse)request.GetResponse(); - - if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - else if (httpResponse.StatusCode != HttpStatusCode.OK) - { - Console.WriteLine("Error sending leave network message"); - } - } - catch (System.Net.Sockets.SocketException) - { - d.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service."); - })); - } - catch (System.Net.WebException e) - { - HttpWebResponse res = (HttpWebResponse)e.Response; - if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - d.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service."); - })); - } - catch - { - Console.WriteLine("Error leaving network: Unknown error"); - } - }); + Task.Factory.StartNew(() => + { + var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; + if (request == null) + { + return; + } + + request.Method = "DELETE"; + request.Timeout = 30000; + + try + { + var httpResponse = (HttpWebResponse)request.GetResponse(); + + if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + else if (httpResponse.StatusCode != HttpStatusCode.OK) + { + Console.WriteLine("Error sending leave network message"); + } + } + catch (System.Net.Sockets.SocketException) + { + d.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service."); + })); + } + catch (System.Net.WebException e) + { + HttpWebResponse res = (HttpWebResponse)e.Response; + if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + d.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service."); + })); + } + catch + { + Console.WriteLine("Error leaving network: Unknown error"); + } + }); } public delegate void PeersCallback(List<ZeroTierPeer> peers); @@ -409,28 +409,28 @@ namespace WinUI try { var httpResponse = (HttpWebResponse)request.GetResponse(); - if (httpResponse.StatusCode == HttpStatusCode.OK) - { - using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) - { - var responseText = streamReader.ReadToEnd(); - //Console.WriteLine(responseText); - List<ZeroTierPeer> peerList = null; - try - { - peerList = JsonConvert.DeserializeObject<List<ZeroTierPeer>>(responseText); - } - catch (JsonReaderException e) - { - Console.WriteLine(e.ToString()); - } - cb(peerList); - } - } - else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } + if (httpResponse.StatusCode == HttpStatusCode.OK) + { + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + //Console.WriteLine(responseText); + List<ZeroTierPeer> peerList = null; + try + { + peerList = JsonConvert.DeserializeObject<List<ZeroTierPeer>>(responseText); + } + catch (JsonReaderException e) + { + Console.WriteLine(e.ToString()); + } + cb(peerList); + } + } + else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } } catch (System.Net.Sockets.SocketException) { @@ -438,15 +438,15 @@ namespace WinUI } catch (System.Net.WebException e) { - HttpWebResponse res = (HttpWebResponse)e.Response; - if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) - { - APIHandler.initHandler(true); - } - else - { - cb(null); - } + HttpWebResponse res = (HttpWebResponse)e.Response; + if (res != null && res.StatusCode == HttpStatusCode.Unauthorized) + { + APIHandler.initHandler(true); + } + else + { + cb(null); + } } } diff --git a/windows/WinUI/NetworkMonitor.cs b/windows/WinUI/NetworkMonitor.cs index ce722e45..927f804c 100644 --- a/windows/WinUI/NetworkMonitor.cs +++ b/windows/WinUI/NetworkMonitor.cs @@ -156,7 +156,7 @@ namespace WinUI { Console.WriteLine("Monitor Thread Exception: " + "\n" + e.StackTrace); } - Console.WriteLine("Monitor Thread Ended"); + Console.WriteLine("Monitor Thread Ended"); } public void SubscribeStatusUpdates(StatusCallback cb) diff --git a/windows/WinUI/OnboardProcess/CreateAccount.xaml b/windows/WinUI/OnboardProcess/CreateAccount.xaml deleted file mode 100644 index ddf50252..00000000 --- a/windows/WinUI/OnboardProcess/CreateAccount.xaml +++ /dev/null @@ -1,38 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.CreateAccount" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*"/> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="Auto"/> - </Grid.ColumnDefinitions> - - <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Margin="10">Email Address:</Label> - <TextBox x:Name="EmailAddressTextBox" Grid.Column="1" Grid.Row="0" Width="150" Margin="10"></TextBox> - - <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" Margin="10">Password:</Label> - <PasswordBox x:Name="PasswordTextBox1" Grid.Column="1" Grid.Row="1" PasswordChar="*" Margin="10"/> - <Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Margin="10">Repeat Password:</Label> - <PasswordBox x:Name="PasswordTextBox2" Grid.Column="1" Grid.Row="2" PasswordChar="*" Margin="10"/> - - <Button Grid.Column="1" Grid.Row="3" Click="CreateAccount_Click" Margin="10" Content="Create Account" Background="#FFFFB354" Width="90" HorizontalAlignment="Right"/> - - <Label x:Name="ErrorText" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Center"></Label> - <Label Grid.Row="5"></Label> - <Button Grid.Column="0" Grid.Row="6" Background="#FFFFB354" Click="BackButton_Click">Go Back</Button> - </Grid> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs b/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs deleted file mode 100644 index 72ba2182..00000000 --- a/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs +++ /dev/null @@ -1,66 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for CreateAccount.xaml - /// </summary> - public partial class CreateAccount : UserControl, ISwitchable - { - public CreateAccount() - { - InitializeComponent(); - } - - public void UtilizeState(object state) - { - throw new NotImplementedException(); - } - - public void CreateAccount_Click(object sender, RoutedEventArgs e) - { - DoCreateAccount(); - } - - public void BackButton_Click(object sender, RoutedEventArgs e) - { - Switcher.Switch(new RegisterOrLogIn()); - } - - public async void DoCreateAccount() - { - if (PasswordTextBox1.Password.ToString() != PasswordTextBox2.Password.ToString()) - { - ErrorText.Content = "Passwords do not match!"; - } - else - { - CentralAPI api = CentralAPI.Instance; - bool accountCreated = await api.Login(EmailAddressTextBox.Text, - PasswordTextBox1.Password.ToString(), true); - - if (accountCreated) - { - Switcher.Switch(new CreateOrJoin()); - } - else - { - ErrorText.Content = "An error ocurred while creating your account."; - } - } - } - } -} diff --git a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml deleted file mode 100644 index 21413e84..00000000 --- a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml +++ /dev/null @@ -1,49 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.CreateOrJoin" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="400"> - <Grid HorizontalAlignment="Stretch" Margin="15"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*"/> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="*"/> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="*"/> - </Grid.ColumnDefinitions> - - <Button Grid.Column="1" x:Name="CreateButton" Content="Create a Network" Background="#FFFFB354" Click="OnCreateButtonClick"/> - - <Label Grid.Column="1" Grid.Row="1" Content="Or" HorizontalAlignment="Center"/> - - <Label Grid.Column="1" Grid.Row="2" Content="Join a Network:" HorizontalAlignment="Center"/> - - <ListBox Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="3" Name="listViewDataBinding" HorizontalContentAlignment="Stretch"> - <ListBox.ItemTemplate> - <DataTemplate> - <Grid HorizontalAlignment="Stretch"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="*"/> - <ColumnDefinition Width="Auto"/> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <TextBlock Grid.Column="0" Grid.Row="0" Margin="5" HorizontalAlignment="Left" Text="{Binding Id}"/> - <TextBlock Grid.Column="1" Grid.Row="0" Margin="5" HorizontalAlignment="Center" Text="{Binding Config.Name}"/> - <Button Grid.Column="2" Grid.Row="0" Margin="5" Content="Join" HorizontalAlignment="Right" Background="#FFFFB354" Tag="{Binding Id}" Click="OnJoinButtonClick"/> - </Grid> - </DataTemplate> - </ListBox.ItemTemplate> - </ListBox> - </Grid> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml.cs b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml.cs deleted file mode 100644 index 91330540..00000000 --- a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml.cs +++ /dev/null @@ -1,98 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for CreateOrJoin.xaml - /// </summary> - public partial class CreateOrJoin : UserControl, ISwitchable - { - private List<CentralNetwork> networkList = new List<CentralNetwork>(); - - public CreateOrJoin() - { - InitializeComponent(); - listViewDataBinding.ItemsSource = networkList; - - GetAvailableNetworks(); - } - - public void UtilizeState(object state) - { - throw new NotImplementedException(); - } - - private async void GetAvailableNetworks() - { - CentralAPI api = CentralAPI.Instance; - - List<CentralNetwork> networks = await api.GetNetworkList(); - - foreach (CentralNetwork n in networks) - { - networkList.Add(n); - } - - listViewDataBinding.Items.Refresh(); - } - - public void OnJoinButtonClick(object sender, RoutedEventArgs e) - { - Button button = sender as Button; - string networkId = button.Tag as string; - - APIHandler handler = APIHandler.Instance; - - handler.JoinNetwork(this.Dispatcher, networkId); - - AuthorizeNetworkMember(networkId); - } - - public void OnCreateButtonClick(object sender, RoutedEventArgs e) - { - CreateNewNetwork(); - } - - private async void CreateNewNetwork() - { - CentralAPI api = CentralAPI.Instance; - - CentralNetwork newNetwork = await api.CreateNewNetwork(); - - APIHandler handler = APIHandler.Instance; - - handler.JoinNetwork(this.Dispatcher, newNetwork.Id); - - AuthorizeNetworkMember(newNetwork.Id); - } - - private async void AuthorizeNetworkMember(string networkId) - { - string nodeId = APIHandler.Instance.NodeAddress(); - - bool authorized = await CentralAPI.Instance.AuthorizeNode(nodeId, networkId); - - if (authorized) - { - Switcher.Switch(new Finished()); - } - else - { - - } - } - } -} diff --git a/windows/WinUI/OnboardProcess/EnterToken.xaml b/windows/WinUI/OnboardProcess/EnterToken.xaml deleted file mode 100644 index 1880167d..00000000 --- a/windows/WinUI/OnboardProcess/EnterToken.xaml +++ /dev/null @@ -1,29 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.EnterToken" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*"/> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="*"/> - </Grid.ColumnDefinitions> - <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="10" TextWrapping="Wrap" HorizontalAlignment="Center" Text="Your API Token can be found or created on https://my.zerotier.com"/> - <TextBlock Grid.Column="0" Grid.Row="1" Text="API Token:" Margin="10"/> - <TextBox x:Name="APITokenInput" Grid.Column="1" Grid.Row="1" Margin="10"/> - - <Button Grid.Column="1" Grid.Row="2" Background="#FFFFB354" Content="Next" HorizontalAlignment="Right" Click="Next_Click" Margin="10"/> - <Label Grid.Row="3"/> - <Button Grid.Column="0" Grid.Row="4" Background="#FFFFB354" Content="Go Back" Click="BackButton_Click" /> - </Grid> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/EnterToken.xaml.cs b/windows/WinUI/OnboardProcess/EnterToken.xaml.cs deleted file mode 100644 index 5d2cc515..00000000 --- a/windows/WinUI/OnboardProcess/EnterToken.xaml.cs +++ /dev/null @@ -1,57 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for EnterToken.xaml - /// </summary> - public partial class EnterToken : UserControl, ISwitchable - { - public EnterToken() - { - InitializeComponent(); - - if (!string.IsNullOrEmpty(CentralAPI.Instance.Central.APIKey)) - { - APITokenInput.Text = CentralAPI.Instance.Central.APIKey; - } - } - - public void UtilizeState(object staqte) - { - - } - - private void Next_Click(object sender, RoutedEventArgs e) - { - CentralAPI api = CentralAPI.Instance; - - if (api.Central.APIKey != APITokenInput.Text) - { - CentralServer server = new CentralServer(); - server.APIKey = APITokenInput.Text; - api.Central = server; - } - - Switcher.Switch(new CreateOrJoin()); - } - - private void BackButton_Click(object sender, RoutedEventArgs e) - { - Switcher.Switch(new RegisterOrLogIn()); - } - } -} diff --git a/windows/WinUI/OnboardProcess/Finished.xaml b/windows/WinUI/OnboardProcess/Finished.xaml deleted file mode 100644 index d29f536c..00000000 --- a/windows/WinUI/OnboardProcess/Finished.xaml +++ /dev/null @@ -1,27 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.Finished" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto" /> - </Grid.ColumnDefinitions> - - <TextBlock Grid.Column="0" Grid.Row="0" Text="All Finished!" HorizontalAlignment="Center"/> - <TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" Text=""/> - <TextBlock Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="2" MaxWidth="270" HorizontalAlignment="Center" Margin="10" Text="You've now joined your first ZeroTier network. Now go to add your other machines!" TextWrapping="Wrap"/> - <TextBlock Grid.Column="0" Grid.Row="3" HorizontalAlignment="Center" Text=""/> - <Button Grid.Column="0" Grid.Row="4" MaxWidth="100" Click="DoneButton_Click" Background="#FFFFB354" Margin="10">Done!</Button> - </Grid> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/Finished.xaml.cs b/windows/WinUI/OnboardProcess/Finished.xaml.cs deleted file mode 100644 index a34abfe2..00000000 --- a/windows/WinUI/OnboardProcess/Finished.xaml.cs +++ /dev/null @@ -1,37 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for Finished.xaml - /// </summary> - public partial class Finished : UserControl, ISwitchable - { - public Finished() - { - InitializeComponent(); - } - public void UtilizeState(object state) - { - throw new NotImplementedException(); - } - - private void DoneButton_Click(object sender, RoutedEventArgs e) - { - Window.GetWindow(this).Close(); - } - } -} diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml b/windows/WinUI/OnboardProcess/LogIn.xaml deleted file mode 100644 index 501f7e0f..00000000 --- a/windows/WinUI/OnboardProcess/LogIn.xaml +++ /dev/null @@ -1,35 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.LogIn" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*" /> - <RowDefinition Height="Auto"/> - </Grid.RowDefinitions> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="Auto"/> - </Grid.ColumnDefinitions> - - <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Margin="10">Email Address:</Label> - <TextBox x:Name="EmailAddressTextBox" Grid.Column="1" Grid.Row="0" MinWidth="150" Margin="10"></TextBox> - - <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" Margin="10">Password:</Label> - <PasswordBox x:Name="PasswordTextBox" Grid.Column="1" Grid.Row="1" PasswordChar="*" Margin="10"/> - - <Button Grid.Column="1" Grid.Row="2" Click="LoginButton_Click" Content="LogIn" Background="#FFFFB354" Width="90" Margin="10" HorizontalAlignment="Right"/> - - <Label x:Name="ErrorText" Grid.Row="3" Grid.ColumnSpan="2" HorizontalAlignment="Center"></Label> - <Label Grid.Row="4"></Label> - <Button Grid.Column="0" Grid.Row="5" Background="#FFFFB354" Click="BackButton_Click">Go Back</Button> - </Grid> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml.cs b/windows/WinUI/OnboardProcess/LogIn.xaml.cs deleted file mode 100644 index 8657b800..00000000 --- a/windows/WinUI/OnboardProcess/LogIn.xaml.cs +++ /dev/null @@ -1,57 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for LogIn.xaml - /// </summary> - public partial class LogIn : UserControl, ISwitchable - { - public LogIn() - { - InitializeComponent(); - } - - public void UtilizeState(object state) - { - throw new NotImplementedException(); - } - - public void LoginButton_Click(object sender, RoutedEventArgs e) - { - DoLogin(); - } - - public void BackButton_Click(object sender, RoutedEventArgs e) - { - Switcher.Switch(new RegisterOrLogIn()); - } - - private async void DoLogin() - { - CentralAPI api = CentralAPI.Instance; - bool didLogIn = await api.Login(EmailAddressTextBox.Text, PasswordTextBox.Password.ToString(), false); - if (didLogIn) - { - Switcher.Switch(new CreateOrJoin()); - } - else - { - ErrorText.Content = "Invalid username or password"; - } - } - } -} diff --git a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml deleted file mode 100644 index 01f3ba9d..00000000 --- a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml +++ /dev/null @@ -1,27 +0,0 @@ -<UserControl x:Class="WinUI.OnboardProcess.RegisterOrLogIn" - 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" - xmlns:local="clr-namespace:WinUI.OnboardProcess" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <StackPanel> - <TextBlock HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" FontFamily="Segoe UI">Welcome to ZeroTier</TextBlock> - <TextBlock HorizontalAlignment="Center" FontSize="16">Let's get started!</TextBlock> - <TextBlock HorizontalAlignment="Center"> </TextBlock> - <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap">If you haven't yet created an account, click "Create Account" below. If you have an account, you can log in with your username/password, or simply enter an API key.</TextBlock> - <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> - <StackPanel.Resources> - <Style TargetType="{x:Type Button}"> - <Setter Property="Margin" Value="10,10,0,0"/> - </Style> - </StackPanel.Resources> - <Button x:Name="CreateAccountButton" Margin="10,5" Content="Create Account" Background="#FFFFB354" Click="CreateAccountButton_Click"/> - - <Button x:Name="LogInButton" Margin="10,5" Content="Log In" Background="#FFFFB354" Click="LogInButton_Click"/> - - <Button x:Name="TokenButton" Margin="10,5" Content="API Token" Background="#FFFFB354" Click="APIToken_Click"/> - </StackPanel> - </StackPanel> -</UserControl> diff --git a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml.cs b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml.cs deleted file mode 100644 index 19c578dd..00000000 --- a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml.cs +++ /dev/null @@ -1,48 +0,0 @@ -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.OnboardProcess -{ - /// <summary> - /// Interaction logic for RegisterOrLogIn.xaml - /// </summary> - public partial class RegisterOrLogIn : UserControl, ISwitchable - { - public RegisterOrLogIn() - { - InitializeComponent(); - } - - public void UtilizeState(object state) - { - throw new NotImplementedException(); - } - - public void CreateAccountButton_Click(object sender, System.Windows.RoutedEventArgs e) - { - Switcher.Switch(new CreateAccount()); - } - - private void LogInButton_Click(object sender, RoutedEventArgs e) - { - Switcher.Switch(new LogIn()); - } - - public void APIToken_Click(object sender, RoutedEventArgs e) - { - Switcher.Switch(new EnterToken()); - } - } -} diff --git a/windows/WinUI/PageSwitcher.xaml b/windows/WinUI/PageSwitcher.xaml deleted file mode 100644 index 2e463e7a..00000000 --- a/windows/WinUI/PageSwitcher.xaml +++ /dev/null @@ -1,13 +0,0 @@ -<Window x:Class="WinUI.PageSwitcher" - 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" - Icon="ZeroTierIcon.ico" - Title="ZeroTier One" Height="300" Width="400"> - <Grid> - - </Grid> -</Window> diff --git a/windows/WinUI/PageSwitcher.xaml.cs b/windows/WinUI/PageSwitcher.xaml.cs deleted file mode 100644 index c9aa659f..00000000 --- a/windows/WinUI/PageSwitcher.xaml.cs +++ /dev/null @@ -1,56 +0,0 @@ -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 PageSwitcher.xaml - /// </summary> - public partial class PageSwitcher : Window - { - public PageSwitcher() - { - InitializeComponent(); - Switcher.pageSwitcher = this; - - CentralAPI api = CentralAPI.Instance; - - if (api.HasAccessToken()) - { - Switcher.Switch(new OnboardProcess.CreateOrJoin()); - } - else - { - Switcher.Switch(new OnboardProcess.RegisterOrLogIn()); - } - } - - public void Navigate(UserControl nextPage) - { - this.Content = nextPage; - } - - public void Navigate(UserControl nextPage, object state) - { - this.Content = nextPage; - ISwitchable s = nextPage as ISwitchable; - - if (s != null) - s.UtilizeState(state); - else - throw new ArgumentException("NextPage is not ISwitchable! " - + nextPage.Name.ToString()); - } - } -} diff --git a/windows/WinUI/Switcher.cs b/windows/WinUI/Switcher.cs deleted file mode 100644 index f48835df..00000000 --- a/windows/WinUI/Switcher.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Controls; -using System.Threading.Tasks; - -namespace WinUI -{ - public static class Switcher - { - public static PageSwitcher pageSwitcher; - - public static void Switch(UserControl newPage) - { - pageSwitcher.Navigate(newPage); - } - - public static void Switch(UserControl newPage, object state) - { - pageSwitcher.Navigate(newPage, state); - } - } -} diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index 2a0d717b..e38f9802 100644 --- a/windows/WinUI/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -45,10 +45,6 @@ namespace WinUI private ObservableCollection<MenuItem> _networkCollection = new ObservableCollection<MenuItem>(); - private static Boolean shouldShowOnboardProcess = true; -#if DEBUG - private static bool isFirstRun = true; -#endif public ObservableCollection<MenuItem> NetworkCollection { @@ -85,23 +81,6 @@ namespace WinUI { if (networks != null) { - if (networks.Count > 0) - { -#if DEBUG - if (isFirstRun) - { - shouldShowOnboardProcess = true; - isFirstRun = false; - } - else - { - shouldShowOnboardProcess = false; - } -#else - shouldShowOnboardProcess = false; -#endif - } - Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { NetworkCollection.Clear(); @@ -116,25 +95,9 @@ namespace WinUI NetworkCollection.Add(item); } })); - - if (shouldShowOnboardProcess) - { - // TODO: Show onboarding process window (on main thread - showOnboardProcess(); - - shouldShowOnboardProcess = false; - } } } - private void showOnboardProcess() - { - Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - PageSwitcher ps = new PageSwitcher(); - ps.Show(); - })); - } private void updateStatus(ZeroTierStatus status) { if (status != null) @@ -144,16 +107,16 @@ namespace WinUI nodeIdMenuItem.Header = "Node ID: " + status.Address; nodeIdMenuItem.IsEnabled = true; nodeId = status.Address; - })); - } - if (CentralAPI.Instance.HasAccessToken()) - { - newNetworkItem.IsEnabled = true; - } - else - { - newNetworkItem.IsEnabled = false; + if (CentralAPI.Instance.HasAccessToken()) + { + newNetworkItem.IsEnabled = true; + } + else + { + newNetworkItem.IsEnabled = false; + } + })); } } @@ -356,10 +319,6 @@ namespace WinUI string nodeId = APIHandler.Instance.NodeAddress(); bool authorized = await CentralAPI.Instance.AuthorizeNode(nodeId, newNetwork.Id); - } - else - { - showOnboardProcess(); } } diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 6bbc1cd7..7a2a1e2b 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -121,34 +121,12 @@ <Compile Include="NetworksPage.xaml.cs"> <DependentUpon>NetworksPage.xaml</DependentUpon> </Compile> - <Compile Include="OnboardProcess\CreateAccount.xaml.cs"> - <DependentUpon>CreateAccount.xaml</DependentUpon> - </Compile> - <Compile Include="OnboardProcess\CreateOrJoin.xaml.cs"> - <DependentUpon>CreateOrJoin.xaml</DependentUpon> - </Compile> - <Compile Include="OnboardProcess\EnterToken.xaml.cs"> - <DependentUpon>EnterToken.xaml</DependentUpon> - </Compile> - <Compile Include="OnboardProcess\Finished.xaml.cs"> - <DependentUpon>Finished.xaml</DependentUpon> - </Compile> - <Compile Include="OnboardProcess\LogIn.xaml.cs"> - <DependentUpon>LogIn.xaml</DependentUpon> - </Compile> - <Compile Include="OnboardProcess\RegisterOrLogIn.xaml.cs"> - <DependentUpon>RegisterOrLogIn.xaml</DependentUpon> - </Compile> - <Compile Include="PageSwitcher.xaml.cs"> - <DependentUpon>PageSwitcher.xaml</DependentUpon> - </Compile> <Compile Include="PeersPage.xaml.cs"> <DependentUpon>PeersPage.xaml</DependentUpon> </Compile> <Compile Include="PreferencesView.xaml.cs"> <DependentUpon>PreferencesView.xaml</DependentUpon> </Compile> - <Compile Include="Switcher.cs" /> <Compile Include="ToolbarItem.xaml.cs"> <DependentUpon>ToolbarItem.xaml</DependentUpon> </Compile> @@ -185,34 +163,6 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="OnboardProcess\CreateAccount.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="OnboardProcess\CreateOrJoin.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="OnboardProcess\EnterToken.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="OnboardProcess\Finished.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="OnboardProcess\LogIn.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="OnboardProcess\RegisterOrLogIn.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> - <Page Include="PageSwitcher.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> <Page Include="PeersPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> |