Network list window opens with click on the menu item

This commit is contained in:
Grant Limberg 2016-11-08 16:31:07 -08:00
parent e1f9f7b6dc
commit 7cf3d2caa1
8 changed files with 57 additions and 42 deletions

View File

@ -19,7 +19,8 @@ namespace WinUI
private string url = null; private string url = null;
private static APIHandler instance; private static volatile APIHandler instance;
private static object syncRoot = new Object();
public static APIHandler Instance public static APIHandler Instance
{ {
@ -27,7 +28,16 @@ namespace WinUI
{ {
if (instance == null) if (instance == null)
{ {
lock (syncRoot)
{
if (instance == null)
{
if (!initHandler())
{
return null;
}
}
}
} }
return instance; return instance;

View File

@ -20,14 +20,12 @@ namespace WinUI
/// </summary> /// </summary>
public partial class NetworkInfoView : UserControl public partial class NetworkInfoView : UserControl
{ {
private APIHandler handler;
private ZeroTierNetwork network; private ZeroTierNetwork network;
public NetworkInfoView(APIHandler handler, ZeroTierNetwork network) public NetworkInfoView(ZeroTierNetwork network)
{ {
InitializeComponent(); InitializeComponent();
this.handler = handler;
this.network = network; this.network = network;
UpdateNetworkData(); UpdateNetworkData();
@ -78,13 +76,13 @@ namespace WinUI
private void leaveButton_Click(object sender, RoutedEventArgs e) 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) private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e)
{ {
CheckBox cb = sender as CheckBox; CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId, APIHandler.Instance.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false, allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false, allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false); allowDefault.IsChecked ?? false);
@ -93,7 +91,7 @@ namespace WinUI
private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e) private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e)
{ {
CheckBox cb = sender as CheckBox; CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId, APIHandler.Instance.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false, allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false, allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false); allowDefault.IsChecked ?? false);
@ -102,7 +100,7 @@ namespace WinUI
private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e) private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e)
{ {
CheckBox cb = sender as CheckBox; CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId, APIHandler.Instance.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false, allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false, allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false); allowDefault.IsChecked ?? false);

View File

@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WinUI" 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"> Title="ZeroTier One" Height="500" Width="500" Icon="ZeroTierIcon.ico">
<Window.Resources> <Window.Resources>

View File

@ -23,9 +23,8 @@ namespace WinUI
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class NetworkList : Window
{ {
APIHandler handler;
Regex charRegex = new Regex("[0-9a-fxA-FX]"); Regex charRegex = new Regex("[0-9a-fxA-FX]");
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
@ -33,20 +32,9 @@ namespace WinUI
bool connected = false; bool connected = false;
public MainWindow() public NetworkList()
{ {
InitializeComponent(); InitializeComponent();
}
public void SetAPIHandler(APIHandler handler)
{
timer.Stop();
timer = new Timer();
this.handler = handler;
networksPage.SetAPIHandler(handler);
updateStatus(); updateStatus();
@ -65,10 +53,9 @@ namespace WinUI
timer.Enabled = true; timer.Enabled = true;
} }
private void updateStatus() private void updateStatus()
{ {
var status = handler.GetStatus(); var status = APIHandler.Instance.GetStatus();
if (status != null) if (status != null)
{ {
@ -108,7 +95,7 @@ namespace WinUI
private void updateNetworks() private void updateNetworks()
{ {
var networks = handler.GetNetworks(); var networks = APIHandler.Instance.GetNetworks();
networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{ {
@ -141,7 +128,7 @@ namespace WinUI
} }
else else
{ {
handler.JoinNetwork(joinNetworkID.Text); APIHandler.Instance.JoinNetwork(joinNetworkID.Text);
} }
} }

View File

@ -20,18 +20,11 @@ namespace WinUI
/// </summary> /// </summary>
public partial class NetworksPage : UserControl public partial class NetworksPage : UserControl
{ {
private APIHandler handler;
public NetworksPage() public NetworksPage()
{ {
InitializeComponent(); InitializeComponent();
} }
public void SetAPIHandler(APIHandler handler)
{
this.handler = handler;
}
public void setNetworks(List<ZeroTierNetwork> networks) public void setNetworks(List<ZeroTierNetwork> networks)
{ {
this.wrapPanel.Children.Clear(); this.wrapPanel.Children.Clear();
@ -44,7 +37,6 @@ namespace WinUI
{ {
this.wrapPanel.Children.Add( this.wrapPanel.Children.Add(
new NetworkInfoView( new NetworkInfoView(
handler,
networks.ElementAt<ZeroTierNetwork>(i))); networks.ElementAt<ZeroTierNetwork>(i)));
} }
} }

View File

@ -15,10 +15,12 @@
PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen"> PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen">
<tb:TaskbarIcon.ContextMenu> <tb:TaskbarIcon.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Header="Node ID: abeb9f9bc5"/> <MenuItem Header="Node ID: abeb9f9bc5"
Click="ToolbarItem_NodeIDClicked"/>
<Separator/> <Separator/>
<MenuItem Header="Join Network..."/> <MenuItem Header="Join Network..."/>
<MenuItem Header="Show Networks..."/> <MenuItem Header="Show Networks..."
Click="ToolbarItem_ShowNetworksClicked"/>
<Separator/> <Separator/>
<MenuItem Header="About..."/> <MenuItem Header="About..."/>
<MenuItem Header="Preferences..."/> <MenuItem Header="Preferences..."/>

View File

@ -24,7 +24,9 @@ namespace WinUI
/// </summary> /// </summary>
public partial class ToolbarItem : Window public partial class ToolbarItem : Window
{ {
APIHandler handler = APIHandler.Instance; private APIHandler handler = APIHandler.Instance;
NetworkList netList = null;
public ToolbarItem() public ToolbarItem()
{ {
@ -40,5 +42,29 @@ namespace WinUI
{ {
Console.WriteLine("PreviewTrayContextMenuOpen"); 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;
}
} }
} }

View File

@ -115,7 +115,7 @@
<Compile Include="ZeroTierPeer.cs" /> <Compile Include="ZeroTierPeer.cs" />
<Compile Include="ZeroTierNetwork.cs" /> <Compile Include="ZeroTierNetwork.cs" />
<Compile Include="ZeroTierStatus.cs" /> <Compile Include="ZeroTierStatus.cs" />
<Page Include="MainWindow.xaml"> <Page Include="NetworkList.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
@ -124,8 +124,8 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="MainWindow.xaml.cs"> <Compile Include="NetworkList.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>NetworkList.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="NetworkInfoView.xaml"> <Page Include="NetworkInfoView.xaml">