diff options
author | Grant Limberg <grant.limberg@zerotier.com> | 2016-11-08 16:31:07 -0800 |
---|---|---|
committer | Grant Limberg <grant.limberg@zerotier.com> | 2016-11-08 16:31:07 -0800 |
commit | 7cf3d2caa19da076ebd3539c8786ce62a53d35f9 (patch) | |
tree | 7d0821d9ac2ba0b1e40a1a0e7903356bf2ea4dab | |
parent | e1f9f7b6dc80a5ad0db3fedc8f5b92d47cbdb1fe (diff) | |
download | infinitytier-7cf3d2caa19da076ebd3539c8786ce62a53d35f9.tar.gz infinitytier-7cf3d2caa19da076ebd3539c8786ce62a53d35f9.zip |
Network list window opens with click on the menu item
-rw-r--r-- | windows/WinUI/APIHandler.cs | 14 | ||||
-rw-r--r-- | windows/WinUI/NetworkInfoView.xaml.cs | 12 | ||||
-rw-r--r-- | windows/WinUI/NetworkList.xaml (renamed from windows/WinUI/MainWindow.xaml) | 2 | ||||
-rw-r--r-- | windows/WinUI/NetworkList.xaml.cs (renamed from windows/WinUI/MainWindow.xaml.cs) | 23 | ||||
-rw-r--r-- | windows/WinUI/NetworksPage.xaml.cs | 8 | ||||
-rw-r--r-- | windows/WinUI/ToolbarItem.xaml | 6 | ||||
-rw-r--r-- | windows/WinUI/ToolbarItem.xaml.cs | 28 | ||||
-rw-r--r-- | windows/WinUI/WinUI.csproj | 6 |
8 files changed, 57 insertions, 42 deletions
diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index f2fb1d21..9cddd916 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -19,7 +19,8 @@ namespace WinUI private string url = null; - private static APIHandler instance; + private static volatile APIHandler instance; + private static object syncRoot = new Object(); public static APIHandler Instance { @@ -27,7 +28,16 @@ namespace WinUI { if (instance == null) { - + lock (syncRoot) + { + if (instance == null) + { + if (!initHandler()) + { + return null; + } + } + } } return instance; diff --git a/windows/WinUI/NetworkInfoView.xaml.cs b/windows/WinUI/NetworkInfoView.xaml.cs index 3ecc31b8..c6c8726e 100644 --- a/windows/WinUI/NetworkInfoView.xaml.cs +++ b/windows/WinUI/NetworkInfoView.xaml.cs @@ -20,14 +20,12 @@ namespace WinUI /// </summary> public partial class NetworkInfoView : UserControl { - private APIHandler handler; private ZeroTierNetwork network; - public NetworkInfoView(APIHandler handler, ZeroTierNetwork network) + public NetworkInfoView(ZeroTierNetwork network) { InitializeComponent(); - this.handler = handler; this.network = network; UpdateNetworkData(); @@ -78,13 +76,13 @@ namespace WinUI private void leaveButton_Click(object sender, RoutedEventArgs e) { - handler.LeaveNetwork(network.NetworkId); + APIHandler.Instance.LeaveNetwork(network.NetworkId); } private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; - handler.JoinNetwork(network.NetworkId, + APIHandler.Instance.JoinNetwork(network.NetworkId, allowManaged.IsChecked ?? false, allowGlobal.IsChecked ?? false, allowDefault.IsChecked ?? false); @@ -93,7 +91,7 @@ namespace WinUI private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; - handler.JoinNetwork(network.NetworkId, + APIHandler.Instance.JoinNetwork(network.NetworkId, allowManaged.IsChecked ?? false, allowGlobal.IsChecked ?? false, allowDefault.IsChecked ?? false); @@ -102,7 +100,7 @@ namespace WinUI private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e) { CheckBox cb = sender as CheckBox; - handler.JoinNetwork(network.NetworkId, + APIHandler.Instance.JoinNetwork(network.NetworkId, allowManaged.IsChecked ?? false, allowGlobal.IsChecked ?? false, allowDefault.IsChecked ?? false); diff --git a/windows/WinUI/MainWindow.xaml b/windows/WinUI/NetworkList.xaml index 9d4a9fc1..6010a990 100644 --- a/windows/WinUI/MainWindow.xaml +++ b/windows/WinUI/NetworkList.xaml @@ -4,7 +4,7 @@ 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.MainWindow" + mc:Ignorable="d" x:Class="WinUI.NetworkList" Title="ZeroTier One" Height="500" Width="500" Icon="ZeroTierIcon.ico"> <Window.Resources> diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/NetworkList.xaml.cs index a57ee4b9..ae5e1c8e 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/NetworkList.xaml.cs @@ -23,9 +23,8 @@ namespace WinUI /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> - public partial class MainWindow : Window + public partial class NetworkList : Window { - APIHandler handler; Regex charRegex = new Regex("[0-9a-fxA-FX]"); Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); @@ -33,20 +32,9 @@ namespace WinUI bool connected = false; - public MainWindow() + public NetworkList() { InitializeComponent(); - } - - - public void SetAPIHandler(APIHandler handler) - { - timer.Stop(); - timer = new Timer(); - - this.handler = handler; - - networksPage.SetAPIHandler(handler); updateStatus(); @@ -64,11 +52,10 @@ namespace WinUI timer.Interval = 2000; timer.Enabled = true; } - private void updateStatus() { - var status = handler.GetStatus(); + var status = APIHandler.Instance.GetStatus(); if (status != null) { @@ -108,7 +95,7 @@ namespace WinUI private void updateNetworks() { - var networks = handler.GetNetworks(); + var networks = APIHandler.Instance.GetNetworks(); networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { @@ -141,7 +128,7 @@ namespace WinUI } else { - handler.JoinNetwork(joinNetworkID.Text); + APIHandler.Instance.JoinNetwork(joinNetworkID.Text); } } diff --git a/windows/WinUI/NetworksPage.xaml.cs b/windows/WinUI/NetworksPage.xaml.cs index 5a0dc19d..e6961350 100644 --- a/windows/WinUI/NetworksPage.xaml.cs +++ b/windows/WinUI/NetworksPage.xaml.cs @@ -20,18 +20,11 @@ namespace WinUI /// </summary> public partial class NetworksPage : UserControl { - private APIHandler handler; - public NetworksPage() { InitializeComponent(); } - public void SetAPIHandler(APIHandler handler) - { - this.handler = handler; - } - public void setNetworks(List<ZeroTierNetwork> networks) { this.wrapPanel.Children.Clear(); @@ -44,7 +37,6 @@ namespace WinUI { this.wrapPanel.Children.Add( new NetworkInfoView( - handler, networks.ElementAt<ZeroTierNetwork>(i))); } } diff --git a/windows/WinUI/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml index 4a153c9a..2a7af229 100644 --- a/windows/WinUI/ToolbarItem.xaml +++ b/windows/WinUI/ToolbarItem.xaml @@ -15,10 +15,12 @@ PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen"> <tb:TaskbarIcon.ContextMenu> <ContextMenu> - <MenuItem Header="Node ID: abeb9f9bc5"/> + <MenuItem Header="Node ID: abeb9f9bc5" + Click="ToolbarItem_NodeIDClicked"/> <Separator/> <MenuItem Header="Join Network..."/> - <MenuItem Header="Show Networks..."/> + <MenuItem Header="Show Networks..." + Click="ToolbarItem_ShowNetworksClicked"/> <Separator/> <MenuItem Header="About..."/> <MenuItem Header="Preferences..."/> diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index 9ff7e860..b3a1aafd 100644 --- a/windows/WinUI/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -24,7 +24,9 @@ namespace WinUI /// </summary> public partial class ToolbarItem : Window { - APIHandler handler = APIHandler.Instance; + private APIHandler handler = APIHandler.Instance; + + NetworkList netList = null; public ToolbarItem() { @@ -40,5 +42,29 @@ namespace WinUI { Console.WriteLine("PreviewTrayContextMenuOpen"); } + + private void ToolbarItem_NodeIDClicked(object sender, System.Windows.RoutedEventArgs e) + { + + } + + private void ToolbarItem_ShowNetworksClicked(object sender, System.Windows.RoutedEventArgs e) + { + if (netList == null) + { + netList = new WinUI.NetworkList(); + netList.Closed += ShowNetworksClosed; + } + + if (!netList.IsVisible) + { + netList.Show(); + } + } + + private void ShowNetworksClosed(object sender, System.EventArgs e) + { + netList = null; + } } } diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 00c07f6c..70e07ba3 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -115,7 +115,7 @@ <Compile Include="ZeroTierPeer.cs" /> <Compile Include="ZeroTierNetwork.cs" /> <Compile Include="ZeroTierStatus.cs" /> - <Page Include="MainWindow.xaml"> + <Page Include="NetworkList.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> @@ -124,8 +124,8 @@ <DependentUpon>App.xaml</DependentUpon> <SubType>Code</SubType> </Compile> - <Compile Include="MainWindow.xaml.cs"> - <DependentUpon>MainWindow.xaml</DependentUpon> + <Compile Include="NetworkList.xaml.cs"> + <DependentUpon>NetworkList.xaml</DependentUpon> <SubType>Code</SubType> </Compile> <Page Include="NetworkInfoView.xaml"> |