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 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;

View File

@ -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);

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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)));
}
}

View File

@ -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..."/>

View File

@ -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;
}
}
}

View File

@ -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">