From 153aca45171b6d7e6ff7fae21d75e43d9863e583 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 11 Nov 2021 21:36:13 +0100 Subject: [PATCH] Implemented option to disable the busy indicator (animation). --- gui/SlunkCryptGUI.xaml | 2 +- gui/SlunkCryptGUI.xaml.cs | 43 ++++++++++++++++++++++++++----------- gui/Utilities/SystemMenu.cs | 32 +++++++++++++-------------- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/gui/SlunkCryptGUI.xaml b/gui/SlunkCryptGUI.xaml index 18e293c..d5da2fd 100644 --- a/gui/SlunkCryptGUI.xaml +++ b/gui/SlunkCryptGUI.xaml @@ -45,7 +45,7 @@ - + diff --git a/gui/SlunkCryptGUI.xaml.cs b/gui/SlunkCryptGUI.xaml.cs index d7a098a..4952a85 100644 --- a/gui/SlunkCryptGUI.xaml.cs +++ b/gui/SlunkCryptGUI.xaml.cs @@ -45,8 +45,9 @@ namespace com.muldersoft.slunkcrypt.gui private readonly ReadOnlyObservableCollection m_logFileReadOnly; private volatile ModeOfOperation m_modeOfOperation = (ModeOfOperation)(-1); - private volatile bool m_busyFlag = false, m_checksumError = false, m_processReceived = false, m_checked = false; + private volatile bool m_busyFlag = false, m_checksumError = false, m_processReceived = false, m_disableAnimation = false; private volatile SlunkCryptRunner m_processRunner = null; + private uint? m_menuId_disableAnimation = null, m_menuId_enableExpertMode = null; private const string ASCII_CHARS = "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"; @@ -58,9 +59,9 @@ namespace com.muldersoft.slunkcrypt.gui { InitializeComponent(); m_defaultStatusText = Label_Status.Text; - m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.SystemIdle, Dispatcher); + m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher); m_dispatcherTimer.Tick += DispatcherTimer_Tick; - m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(125); + m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); m_logFileReadOnly = new ReadOnlyObservableCollection(m_logFile); } @@ -76,8 +77,20 @@ namespace com.muldersoft.slunkcrypt.gui } set { - m_dispatcherTimer.IsEnabled = m_busyFlag = value; - NotifyPropertyChanged("IsBusy"); + if (m_busyFlag != value) + { + m_dispatcherTimer.IsEnabled = (m_busyFlag = value) && (!m_disableAnimation); + NotifyPropertyChanged("IsBusy"); + NotifyPropertyChanged("IsBusyIndicatorVisible"); + } + } + } + + public bool IsBusyIndicatorVisible + { + get + { + return m_busyFlag && (!m_disableAnimation); } } @@ -357,7 +370,9 @@ namespace com.muldersoft.slunkcrypt.gui private async void Window_Loaded(object sender, RoutedEventArgs e) { await Task.Yield(); - new SystemMenu(this).AppendMenu("Enable Expert Mode", SystemMenu_Activated); + SystemMenu systemMenu = new SystemMenu(this, SystemMenu_Activated); + m_menuId_disableAnimation = systemMenu.AppendMenu("Disable Busy Indicator"); + m_menuId_enableExpertMode = systemMenu.AppendMenu("Expert Settings"); CreateIndicatorElements(); } @@ -377,19 +392,23 @@ namespace com.muldersoft.slunkcrypt.gui private void SystemMenu_Activated(SystemMenu sender, uint menuId) { - if (m_checked = (!m_checked)) + if (m_menuId_disableAnimation.HasValue && (menuId == m_menuId_disableAnimation.Value)) + { + sender.ModifyMenu(menuId, m_disableAnimation = !m_disableAnimation); + if (m_busyFlag) + { + m_dispatcherTimer.IsEnabled = !m_disableAnimation; + NotifyPropertyChanged("IsBusyIndicatorVisible"); + } + } + else if (m_menuId_enableExpertMode.HasValue && (menuId == m_menuId_enableExpertMode.Value)) { - sender.ModifyMenu(menuId, true); try { Process.Start("https://youtu.be/Is_8bjYVmnA").Dispose(); } catch { } } - else - { - sender.ModifyMenu(menuId, false); - } } // ============================================================================= diff --git a/gui/Utilities/SystemMenu.cs b/gui/Utilities/SystemMenu.cs index 06b9f5e..401e721 100644 --- a/gui/Utilities/SystemMenu.cs +++ b/gui/Utilities/SystemMenu.cs @@ -11,15 +11,14 @@ using System.Windows.Interop; namespace com.muldersoft.slunkcrypt.gui.utils { - using ItemInfo = Tuple; - class SystemMenu : IDisposable { private const int WM_SYSCOMMAND = 0x112; public delegate void SystemMenuActionHandler(SystemMenu sender, uint menuId); + private readonly SystemMenuActionHandler m_handler; private readonly HwndSource m_hwndSource; - private readonly Dictionary m_menuItems = new Dictionary(); + private readonly Dictionary m_menuItems = new Dictionary(); private bool m_firstItem = true; private uint m_nextMenuId = 100; @@ -30,12 +29,16 @@ namespace com.muldersoft.slunkcrypt.gui.utils // Constructor // ============================================================================= - public SystemMenu(Window window) + public SystemMenu(Window window, SystemMenuActionHandler handler) { if (ReferenceEquals(window, null)) { throw new ArgumentNullException("Window must not be null!"); } + if (ReferenceEquals(m_handler = handler, null)) + { + throw new ArgumentNullException("SystemMenuActionHandler must not be null!"); + } window.Dispatcher.VerifyAccess(); m_hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle); m_hwndSource.AddHook(WndProcHook); @@ -45,16 +48,12 @@ namespace com.muldersoft.slunkcrypt.gui.utils // Public methods // ============================================================================= - public uint AppendMenu(string captionStr, SystemMenuActionHandler handler) + public uint AppendMenu(string captionStr) { if (m_disposed) { throw new ObjectDisposedException("Already disposed!"); } - if (ReferenceEquals(handler, null)) - { - throw new ArgumentNullException("SystemMenuActionHandler must not be null!"); - } m_hwndSource.Dispatcher.VerifyAccess(); IntPtr hSysMenu = GetSystemMenu(m_hwndSource.Handle, false); if (hSysMenu != IntPtr.Zero) @@ -69,7 +68,7 @@ namespace com.muldersoft.slunkcrypt.gui.utils if (AppendMenu(hSysMenu, Native.MenuFlags.MF_STRING, m_nextMenuId, captionStr)) { uint menuItemId = m_nextMenuId++; - m_menuItems.Add(menuItemId, Tuple.Create(captionStr, handler)); + m_menuItems.Add(menuItemId, captionStr); return menuItemId; } } @@ -83,13 +82,13 @@ namespace com.muldersoft.slunkcrypt.gui.utils throw new ObjectDisposedException("Already disposed!"); } m_hwndSource.Dispatcher.VerifyAccess(); - ItemInfo itemInfo; - if (m_menuItems.TryGetValue(menuId, out itemInfo)) + string captionStr; + if (m_menuItems.TryGetValue(menuId, out captionStr)) { IntPtr hSysMenu = GetSystemMenu(m_hwndSource.Handle, false); if (hSysMenu != IntPtr.Zero) { - return ModifyMenu(hSysMenu, menuId, Native.MenuFlags.MF_BYCOMMAND | (isChecked ? Native.MenuFlags.MF_CHECKED : Native.MenuFlags.MF_UNCHECKED), menuId, itemInfo.Item1); + return ModifyMenu(hSysMenu, menuId, Native.MenuFlags.MF_BYCOMMAND | (isChecked ? Native.MenuFlags.MF_CHECKED : Native.MenuFlags.MF_UNCHECKED), menuId, captionStr); } return false; } @@ -107,11 +106,10 @@ namespace com.muldersoft.slunkcrypt.gui.utils { if (msg == WM_SYSCOMMAND) { - uint menuId = (uint)wParam.ToInt32(); - ItemInfo itemInfo; - if (m_menuItems.TryGetValue(menuId, out itemInfo)) + uint menuId; + if (m_menuItems.ContainsKey(menuId = (uint) wParam.ToInt32())) { - itemInfo.Item2(this, menuId); + m_handler(this, menuId); handled = true; } }