From 6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 14:54:55 -0800 Subject: [PATCH] starts up to a toolbar icon with context menu. still much more to do --- windows/WinUI/App.xaml | 2 +- windows/WinUI/App.xaml.cs | 8 ++ windows/WinUI/MainWindow.xaml.cs | 107 +++------------ .../WinUI/Properties/Resources.Designer.cs | 52 +++---- windows/WinUI/Properties/Resources.resx | 17 ++- windows/WinUI/Resources/ZeroTierIcon.ico | Bin 0 -> 45451 bytes windows/WinUI/Simple Styles.xaml | 9 +- windows/WinUI/ToolbarItem.xaml | 32 +++++ windows/WinUI/ToolbarItem.xaml.cs | 127 ++++++++++++++++++ windows/WinUI/WinUI.csproj | 14 ++ 10 files changed, 249 insertions(+), 119 deletions(-) create mode 100644 windows/WinUI/Resources/ZeroTierIcon.ico create mode 100644 windows/WinUI/ToolbarItem.xaml create mode 100644 windows/WinUI/ToolbarItem.xaml.cs diff --git a/windows/WinUI/App.xaml b/windows/WinUI/App.xaml index 08b9b7921..12ed85f9a 100644 --- a/windows/WinUI/App.xaml +++ b/windows/WinUI/App.xaml @@ -1,7 +1,7 @@  + StartupUri="ToolbarItem.xaml"> diff --git a/windows/WinUI/App.xaml.cs b/windows/WinUI/App.xaml.cs index a97edde74..53ef2f678 100644 --- a/windows/WinUI/App.xaml.cs +++ b/windows/WinUI/App.xaml.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; +using Hardcodet.Wpf.TaskbarNotification; namespace WinUI { @@ -13,5 +14,12 @@ namespace WinUI /// public partial class App : Application { + private TaskbarIcon tb; + + private void InitApplication() + { + tb = (TaskbarIcon)FindResource("NotifyIcon"); + tb.Visibility = Visibility.Visible; + } } } diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index 25534b465..a57ee4b9a 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -36,102 +36,35 @@ namespace WinUI public MainWindow() { InitializeComponent(); - - if (InitAPIHandler()) - { - networksPage.SetAPIHandler(handler); - - updateStatus(); - if (!connected) - { - MessageBox.Show("Unable to connect to ZeroTier Service."); - } - - updateNetworks(); - //updatePeers(); - - DataObject.AddPastingHandler(joinNetworkID, OnPaste); - - timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); - timer.Interval = 2000; - timer.Enabled = true; - } } - private String readAuthToken(String path) + public void SetAPIHandler(APIHandler handler) { - String authToken = ""; + timer.Stop(); + timer = new Timer(); - if (File.Exists(path)) + this.handler = handler; + + networksPage.SetAPIHandler(handler); + + updateStatus(); + + if (!connected) { - try - { - byte[] tmp = File.ReadAllBytes(path); - authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); - } - catch - { - MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); - } + MessageBox.Show("Unable to connect to ZerOTier Service"); + return; } - return authToken; - } - - private Int32 readPort(String path) - { - Int32 port = 9993; - - try - { - byte[] tmp = File.ReadAllBytes(path); - port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); - if ((port <= 0) || (port > 65535)) - port = 9993; - } - catch - { - } - - return port; - } - - private bool InitAPIHandler() - { - String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; - String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; - - String authToken = ""; - Int32 port = 9993; - - if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) - { - // launch external process to copy file into place - 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); - startInfo.Verb = "runas"; - - - var process = Process.Start(startInfo); - process.WaitForExit(); - } - - authToken = readAuthToken(localZtDir + "\\authtoken.secret"); - - if ((authToken == null) || (authToken.Length <= 0)) - { - MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); - this.Close(); - return false; - } - - port = readPort(localZtDir + "\\zerotier-one.port"); - handler = new APIHandler(port, authToken); - return true; + updateNetworks(); + + DataObject.AddPastingHandler(joinNetworkID, OnPaste); + + timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); + timer.Interval = 2000; + timer.Enabled = true; } + private void updateStatus() { diff --git a/windows/WinUI/Properties/Resources.Designer.cs b/windows/WinUI/Properties/Resources.Designer.cs index 57a56f7d0..3e5c78aee 100644 --- a/windows/WinUI/Properties/Resources.Designer.cs +++ b/windows/WinUI/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace WinUI.Properties -{ - - +namespace WinUI.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -22,50 +22,52 @@ namespace WinUI.Properties [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinUI.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon ZeroTierIcon { + get { + object obj = ResourceManager.GetObject("ZeroTierIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/windows/WinUI/Properties/Resources.resx b/windows/WinUI/Properties/Resources.resx index af7dbebba..0872fceb9 100644 --- a/windows/WinUI/Properties/Resources.resx +++ b/windows/WinUI/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,13 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\ZeroTierIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/windows/WinUI/Resources/ZeroTierIcon.ico b/windows/WinUI/Resources/ZeroTierIcon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5d06b9f2857b39f0b5d3395e3e7999ba6bcc3a38 GIT binary patch literal 45451 zcmZQzU}WHA00Bk@4hCUv28L-23=9SaAaM?c6?_Z~E4djM6cnI*4hDumDFy}s0SG^X zm4V@>5=b|QufX8N!@!WJ!NB0)0O4ymF)*w)ftjbkutJrA;c^+wJOzdo0t^h*b71Bv zFl4YWFetBOVCW3+bLZuf;$mQ6;Pv!y2?Ci0!W?W23=A*c6_+M zhr_k3tjzC;>y{(A3_mX1c3`>nREweJMXnOl+rmOV2fH6NKi)pto8AAC;lsi2&EGf5 zsxcp6zpsAp^0S%T4APzXd-k6-5@j&!lc<+S zavk%BPfxvXdR%(-D$B~k;>7wzo-PjNri?3o9p1ln>r^?rniK5tj7kfp@1ESS>3V!* zr04f{cOM^K-y)NDcW3ePVu>*JbDTZrLm8eN)|b9@?3h~}Ym@-v+z^%ptIYk)HtgNI zcMn@`M}u9S8w096Mt1WU3 zoARf;`D^(yU05(<{!hUJ-@cW_HMzPhh<(QV;qUkVXS_FbacntW!!XbO{(0{WJsevO z*D%a@`Dw|G&Pz{`pqLzPdlYaZa-L z{y&I{lRE$CQPQmW^Ur5reH7ht%$;HKR zrOxlq|GR(voBQ{-?cBL@%a$!uuCLm#)cjb@F?``u>A1G#gaP9SuW##uP z&DS&j?`NFnKf|gMTmLJa;dIbv zdT`<)oayl$!Zc@kfW&lp4;OXWpZ(u;hH!&3%Yn|i>;Jk9)EU}28kmcc-lyCDt&EfQ z`L}=b=FOG769pOA`*weeZ?R+)U^%eE5u&t-LBjkD*enJ{gS;7FqZpVHZft-^vmDqE zxbClbqMt(!5)%}8zZrFObe7!zzwS=`;?Vm4$1i_*adGjUYx3t=AJj3dJIVgw^ZuH7 z|NhRee;WR0^8C=cXO8l9TlyJH9_)U<&v$$NeNgH1S-bA!c@6v3f6iR!XE1s4;D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e~%R^~GU&u)+$OdU)g$P5sM@d?o&wa6Hz9%e4c z4tyA<4yF%g7K{%%2Ml@c6vPIJ!Q?^ev9V$1;5gV-Q3 zWcAqCFmpk6;KML=$Yy}-fbl`|Par-r28qGsk;Or5m^jQ_e0GE6VCrD{KxTk2j1QVK z1@VzFNDL;AEDmDB#9`)w?7)X%>R|dnW`Hn=51Q))v9V#097qki97qg=Vdmnq8zcu) z2hsz=F!Mlc7zWLK!^A;sm^g?AiGyemMrOmz1=)cQ!_CX^;}oPBh$!sgVr8{?7)YqX+NoUgWN?e`^mAJTK1D`H#Yl` zVe~5L@ z==c{2fejuu`2YX^4+aML4-5?aRK_4P?LROu)PG=L`2T@{@&5+~=KnuH``DlsgT^U9 z!xEse3fMS>0}BZrAW + @@ -1118,4 +1123,6 @@ + + diff --git a/windows/WinUI/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml new file mode 100644 index 000000000..4a153c9a8 --- /dev/null +++ b/windows/WinUI/ToolbarItem.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs new file mode 100644 index 000000000..e34863dd4 --- /dev/null +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -0,0 +1,127 @@ +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; +using System.Text.RegularExpressions; +using System.Timers; +using System.Windows.Threading; +using System.IO; +using System.Diagnostics; + +namespace WinUI +{ + /// + /// Interaction logic for ToolbarItem.xaml + /// + public partial class ToolbarItem : Window + { + APIHandler handler; + + public ToolbarItem() + { + InitializeComponent(); + + if (InitAPIHandler()) + { + + } + else + { + MessageBox.Show("ZeroTier API Initialization Failed"); + } + } + + private String readAuthToken(String path) + { + String authToken = ""; + + if (File.Exists(path)) + { + try + { + byte[] tmp = File.ReadAllBytes(path); + authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); + } + catch + { + MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); + } + } + + return authToken; + } + + private Int32 readPort(String path) + { + Int32 port = 9993; + + try + { + byte[] tmp = File.ReadAllBytes(path); + port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); + if ((port <= 0) || (port > 65535)) + port = 9993; + } + catch + { + } + + return port; + } + + private bool InitAPIHandler() + { + String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; + String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; + + String authToken = ""; + Int32 port = 9993; + + if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) + { + // launch external process to copy file into place + 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); + startInfo.Verb = "runas"; + + + var process = Process.Start(startInfo); + process.WaitForExit(); + } + + authToken = readAuthToken(localZtDir + "\\authtoken.secret"); + + if ((authToken == null) || (authToken.Length <= 0)) + { + MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); + this.Close(); + return false; + } + + port = readPort(localZtDir + "\\zerotier-one.port"); + handler = new APIHandler(port, authToken); + return true; + } + + private void ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("TrayContextMenuOpen"); + } + + private void ToolbarItem_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("PreviewTrayContextMenuOpen"); + } + } +} diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 181983c09..00c07f6ce 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -66,6 +66,10 @@ + + ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll + True + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -104,6 +108,9 @@ PeersPage.xaml + + ToolbarItem.xaml + @@ -141,6 +148,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + @@ -214,6 +225,9 @@ + + +