summaryrefslogtreecommitdiff
path: root/windows/WinUI
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-08 14:54:55 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-08 14:54:55 -0800
commit6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee (patch)
tree28dea243c77542335bf745882dd02e6c27b4e5eb /windows/WinUI
parent54206fd44d5bda4b9fd0f5dacbaefdbe81e15b18 (diff)
downloadinfinitytier-6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee.tar.gz
infinitytier-6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee.zip
starts up to a toolbar icon with context menu. still much more to do
Diffstat (limited to 'windows/WinUI')
-rw-r--r--windows/WinUI/App.xaml2
-rw-r--r--windows/WinUI/App.xaml.cs8
-rw-r--r--windows/WinUI/MainWindow.xaml.cs97
-rw-r--r--windows/WinUI/Properties/Resources.Designer.cs52
-rw-r--r--windows/WinUI/Properties/Resources.resx17
-rw-r--r--windows/WinUI/Resources/ZeroTierIcon.icobin0 -> 45451 bytes
-rw-r--r--windows/WinUI/Simple Styles.xaml9
-rw-r--r--windows/WinUI/ToolbarItem.xaml32
-rw-r--r--windows/WinUI/ToolbarItem.xaml.cs127
-rw-r--r--windows/WinUI/WinUI.csproj14
10 files changed, 244 insertions, 114 deletions
diff --git a/windows/WinUI/App.xaml b/windows/WinUI/App.xaml
index 08b9b792..12ed85f9 100644
--- a/windows/WinUI/App.xaml
+++ b/windows/WinUI/App.xaml
@@ -1,7 +1,7 @@
<Application x:Class="WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- StartupUri="MainWindow.xaml">
+ StartupUri="ToolbarItem.xaml">
<Application.Resources>
<ResourceDictionary>
diff --git a/windows/WinUI/App.xaml.cs b/windows/WinUI/App.xaml.cs
index a97edde7..53ef2f67 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
/// </summary>
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 25534b46..a57ee4b9 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)
- {
- 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)
+ public void SetAPIHandler(APIHandler handler)
{
- Int32 port = 9993;
+ timer.Stop();
+ timer = new Timer();
- try
- {
- byte[] tmp = File.ReadAllBytes(path);
- port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
- if ((port <= 0) || (port > 65535))
- port = 9993;
- }
- catch
- {
- }
+ this.handler = handler;
- return port;
- }
+ networksPage.SetAPIHandler(handler);
- 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;
+ updateStatus();
- if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port"))
+ if (!connected)
{
- // 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();
+ MessageBox.Show("Unable to connect to ZerOTier Service");
+ return;
}
- authToken = readAuthToken(localZtDir + "\\authtoken.secret");
+ updateNetworks();
- if ((authToken == null) || (authToken.Length <= 0))
- {
- MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One");
- this.Close();
- return false;
- }
+ DataObject.AddPastingHandler(joinNetworkID, OnPaste);
- port = readPort(localZtDir + "\\zerotier-one.port");
- handler = new APIHandler(port, authToken);
- return true;
+ 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 57a56f7d..3e5c78ae 100644
--- a/windows/WinUI/Properties/Resources.Designer.cs
+++ b/windows/WinUI/Properties/Resources.Designer.cs
@@ -8,10 +8,10 @@
// </auto-generated>
//------------------------------------------------------------------------------
-namespace WinUI.Properties
-{
-
-
+namespace WinUI.Properties {
+ using System;
+
+
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@@ -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() {
}
-
+
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
-
+
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[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;
}
}
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
+ /// </summary>
+ 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 af7dbebb..0872fceb 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.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@@ -109,9 +112,13 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <data name="ZeroTierIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\ZeroTierIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
</root> \ 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 00000000..5d06b9f2
--- /dev/null
+++ b/windows/WinUI/Resources/ZeroTierIcon.ico
Binary files differ
diff --git a/windows/WinUI/Simple Styles.xaml b/windows/WinUI/Simple Styles.xaml
index f2ddedf9..a03348b3 100644
--- a/windows/WinUI/Simple Styles.xaml
+++ b/windows/WinUI/Simple Styles.xaml
@@ -1,4 +1,9 @@
-<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ xmlns:tb="http://www.hardcodet.net/taskbar">
<!-- SimpleStyles.XAML defines a set of control styles which are simplified starting points for creating your own controls -->
@@ -1118,4 +1123,6 @@
</Setter.Value>
</Setter>
</Style>
+
+ <tb:TaskbarIcon x:Key="NotifyIcon" IconSource="ZeroTierIcon.ico" ToolTipText="ZeroTier One"/>
</ResourceDictionary>
diff --git a/windows/WinUI/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml
new file mode 100644
index 00000000..4a153c9a
--- /dev/null
+++ b/windows/WinUI/ToolbarItem.xaml
@@ -0,0 +1,32 @@
+<Window x:Class="WinUI.ToolbarItem"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:local="clr-namespace:WinUI"
+ xmlns:tb="http://www.hardcodet.net/taskbar"
+ mc:Ignorable="d"
+ Height="300" Width="300" Visibility="Hidden">
+ <Grid>
+ <tb:TaskbarIcon x:Name="MyNotifyIcon"
+ IconSource="ZeroTierIcon.ico"
+ ToolTipText="ZeroTier One"
+ TrayContextMenuOpen="ToolbarItem_TrayContextMenuOpen"
+ PreviewTrayContextMenuOpen="ToolbarItem_PreviewTrayContextMenuOpen">
+ <tb:TaskbarIcon.ContextMenu>
+ <ContextMenu>
+ <MenuItem Header="Node ID: abeb9f9bc5"/>
+ <Separator/>
+ <MenuItem Header="Join Network..."/>
+ <MenuItem Header="Show Networks..."/>
+ <Separator/>
+ <MenuItem Header="About..."/>
+ <MenuItem Header="Preferences..."/>
+ <Separator/>
+ <MenuItem Header="Quit"/>
+ </ContextMenu>
+ </tb:TaskbarIcon.ContextMenu>
+
+ </tb:TaskbarIcon>
+ </Grid>
+</Window>
diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs
new file mode 100644
index 00000000..e34863dd
--- /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
+{
+ /// <summary>
+ /// Interaction logic for ToolbarItem.xaml
+ /// </summary>
+ 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 181983c0..00c07f6c 100644
--- a/windows/WinUI/WinUI.csproj
+++ b/windows/WinUI/WinUI.csproj
@@ -66,6 +66,10 @@
<PropertyGroup />
<ItemGroup>
<Reference Include="Accessibility" />
+ <Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@@ -104,6 +108,9 @@
<Compile Include="PeersPage.xaml.cs">
<DependentUpon>PeersPage.xaml</DependentUpon>
</Compile>
+ <Compile Include="ToolbarItem.xaml.cs">
+ <DependentUpon>ToolbarItem.xaml</DependentUpon>
+ </Compile>
<Compile Include="ZeroTierPeerPhysicalPath.cs" />
<Compile Include="ZeroTierPeer.cs" />
<Compile Include="ZeroTierNetwork.cs" />
@@ -141,6 +148,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="ToolbarItem.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
</ItemGroup>
<ItemGroup>
<Compile Include="NetworkInfoView.xaml.cs">
@@ -214,6 +225,9 @@
</BlendEmbeddedFont>
<Resource Include="ZeroTierIcon.ico" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\ZeroTierIcon.ico" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Expression\Blend\.NETFramework\v4.5\Microsoft.Expression.Blend.WPF.targets" />
<PropertyGroup>