From d29dfe059593e40d6daf0d377ac85ae1ce1109f3 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Sat, 5 Dec 2020 22:27:53 -0500 Subject: [PATCH] bump version - UI changes around context menu and allow it to right-click/close --- DesktopEdge/MainWindow.xaml.cs | 66 +++++++++++++++++++++++++----- ZitiUpdateService/UpdateService.cs | 2 +- version | 2 +- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/DesktopEdge/MainWindow.xaml.cs b/DesktopEdge/MainWindow.xaml.cs index 8e733ef3..330595ea 100644 --- a/DesktopEdge/MainWindow.xaml.cs +++ b/DesktopEdge/MainWindow.xaml.cs @@ -45,7 +45,7 @@ namespace ZitiDesktopEdge { public static string ExpectedLogPathRoot; public static string ExpectedLogPathUI; public static string ExpectedLogPathServices; - + static MainWindow() { var asm = System.Reflection.Assembly.GetExecutingAssembly(); ThisAssemblyName = asm.GetName().Name; @@ -65,17 +65,19 @@ namespace ZitiDesktopEdge { } } - private void AddIdentity(ZitiIdentity id) { + private void AddIdentity(ZitiIdentity id) { semaphoreSlim.Wait(); if (!identities.Any(i => id.Fingerprint == i.Fingerprint)) { identities.Add(id); } semaphoreSlim.Release(); - } + } + private System.Windows.Forms.ContextMenu contextMenu; + private System.Windows.Forms.MenuItem contextMenuItem; + private System.ComponentModel.IContainer components; public MainWindow() { InitializeComponent(); - string nlogFile = Path.Combine(ExecutionDirectory, ThisAssemblyName + "-log.config"); bool byFile = false; @@ -108,17 +110,52 @@ namespace ZitiDesktopEdge { App.Current.MainWindow.Closing += MainWindow_Closing; App.Current.MainWindow.Deactivated += MainWindow_Deactivated; App.Current.MainWindow.Activated += MainWindow_Activated; + + + this.components = new System.ComponentModel.Container(); + this.contextMenu = new System.Windows.Forms.ContextMenu(); + this.contextMenuItem = new System.Windows.Forms.MenuItem(); + this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.contextMenuItem }); + + this.contextMenuItem.Index = 0; + this.contextMenuItem.Text = "&Close UI"; + this.contextMenuItem.Click += new System.EventHandler(this.contextMenuItem_Click); + + notifyIcon = new System.Windows.Forms.NotifyIcon(); notifyIcon.Visible = true; notifyIcon.Click += TargetNotifyIcon_Click; notifyIcon.Visible = true; + notifyIcon.BalloonTipClosed += NotifyIcon_BalloonTipClosed; + notifyIcon.MouseClick += NotifyIcon_MouseClick; + notifyIcon.ContextMenu = this.contextMenu; + IdentityMenu.OnDetach += OnDetach; MainMenu.OnDetach += OnDetach; SetNotifyIcon("white"); } + private void contextMenuItem_Click(object Sender, EventArgs e) { + this.Close(); + } - private void Window_MouseDown(object sender, MouseButtonEventArgs e) { + private void NotifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { + if (e.Button == System.Windows.Forms.MouseButtons.Left) { + //Do the awesome left clickness + } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { + //Do the wickedy right clickness + } else { + //Some other button from the enum :) + } + } + + private void NotifyIcon_BalloonTipClosed(object sender, EventArgs e) { + var thisIcon = (System.Windows.Forms.NotifyIcon)sender; + thisIcon.Visible = false; + thisIcon.Dispose(); + } + + private void Window_MouseDown(object sender, MouseButtonEventArgs e) { OnDetach(e); } @@ -148,9 +185,13 @@ namespace ZitiDesktopEdge { } private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - notifyIcon.Visible = false; - //notifyIcon.Icon.Dispose(); - //notifyIcon.Dispose(); + if (notifyIcon != null) { + notifyIcon.Visible = false; + notifyIcon.Icon.Dispose(); + notifyIcon.Dispose(); + notifyIcon = null; + } + Application.Current.Shutdown(); } private void SetCantDisplay(string title, string detailMessage, Visibility closeButtonVisibility) { @@ -239,8 +280,11 @@ namespace ZitiDesktopEdge { } private void MonitorClient_OnServiceStatusEvent(object sender, MonitorServiceStatusEvent evt) { - if (evt.Status == "upgrading") { + if (evt.Message?.ToLower() == "upgrading") { logger.Info("The monitor has indicated an upgrade is in progress. Shutting down the UI"); + notifyIcon.Visible = false; + notifyIcon.Icon.Dispose(); + notifyIcon.Dispose(); Application.Current.Shutdown(); } logger.Debug("MonitorClient_OnServiceStatusEvent: {0}", evt.Status); @@ -572,8 +616,8 @@ namespace ZitiDesktopEdge { } private void SetNotifyIcon(string iconPrefix) { var iconUri = new Uri("pack://application:,,/Assets/Images/ziti-" + iconPrefix + ".ico"); - System.IO.Stream iconStream = System.Windows.Application.GetResourceStream(iconUri).Stream; - notifyIcon.Icon = new System.Drawing.Icon(iconStream); + Stream iconStream = Application.GetResourceStream(iconUri).Stream; + notifyIcon.Icon = new Icon(iconStream); Application.Current.MainWindow.Icon = System.Windows.Media.Imaging.BitmapFrame.Create(iconUri); } diff --git a/ZitiUpdateService/UpdateService.cs b/ZitiUpdateService/UpdateService.cs index f4561279..6578e7c3 100644 --- a/ZitiUpdateService/UpdateService.cs +++ b/ZitiUpdateService/UpdateService.cs @@ -526,7 +526,7 @@ namespace ZitiUpdateService { }; EventRegistry.SendEventToConsumers(status); - await Task.Delay(500); //wait for the event to send and give the UI time to close... + await Task.Delay(1000); //wait for the event to send and give the UI time to close... stopProcessForcefully("ZitiDesktopEdge", "UI"); } diff --git a/version b/version index d4ca9156..5577648b 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.6.13 +1.6.14