diff options
Diffstat (limited to 'windows/WinUI/ToolbarItem.xaml.cs')
-rw-r--r-- | windows/WinUI/ToolbarItem.xaml.cs | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index 29791a4e..c16de3c3 100644 --- a/windows/WinUI/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; +using System.Net.Http; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -44,6 +45,11 @@ 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 { get { return _networkCollection; } @@ -79,13 +85,30 @@ namespace WinUI { if (networks != null) { - this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + 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(); foreach (ZeroTierNetwork n in networks) { MenuItem item = new MenuItem(); - item.Header = n.Title; + item.Header = n.Title.Replace("_", "__"); item.DataContext = n; item.IsChecked = n.IsConnected; item.Click += ToolbarItem_NetworkClicked; @@ -93,6 +116,18 @@ namespace WinUI NetworkCollection.Add(item); } })); + + if (shouldShowOnboardProcess) + { + // TODO: Show onboarding process window (on main thread + Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + PageSwitcher ps = new PageSwitcher(); + ps.Show(); + })); + + shouldShowOnboardProcess = false; + } } } @@ -111,7 +146,19 @@ namespace WinUI private void ToolbarItem_NodeIDClicked(object sender, System.Windows.RoutedEventArgs e) { - Clipboard.SetText(nodeId); + try + { + Clipboard.SetDataObject(nodeId); + } + catch (ArgumentNullException) + { + // tried to copy a null nodeId + Console.WriteLine("ArgumentNullException"); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } } private void ToolbarItem_ShowNetworksClicked(object sender, System.Windows.RoutedEventArgs e) @@ -182,6 +229,11 @@ namespace WinUI joinNetView = null; } + private void ToolbarItem_CentralClicked(object sender, System.EventArgs e) + { + Process.Start("https://my.zerotier.com"); + } + private void ToolbarItem_AboutClicked(object sender, System.EventArgs e) { if (aboutView == null) @@ -255,7 +307,7 @@ namespace WinUI private void ToolbarItem_QuitClicked(object sender, System.EventArgs e) { NetworkMonitor.Instance.StopMonitor(); - this.Close(); + Close(); Application.Current.Shutdown(); } @@ -269,11 +321,11 @@ namespace WinUI ZeroTierNetwork network = item.DataContext as ZeroTierNetwork; if (item.IsChecked) { - APIHandler.Instance.LeaveNetwork(network.NetworkId); + APIHandler.Instance.LeaveNetwork(Dispatcher, network.NetworkId); } else { - APIHandler.Instance.JoinNetwork(network.NetworkId, network.AllowManaged, network.AllowGlobal, network.AllowDefault); + APIHandler.Instance.JoinNetwork(Dispatcher, network.NetworkId, network.AllowManaged, network.AllowGlobal, network.AllowDefault); } } } |