From 9189b0629d9169af37e015b8fee4b05dd0de708a Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Mon, 25 Oct 2021 18:55:34 +0200 Subject: [PATCH] [BUG] Do not restart if DisplayChange was due to STM open (#223), version 1.0.24.1 --- Business/App.cs | 19 +++++++++++-------- Business/KeyboardInput.cs | 6 +----- Business/Menus.cs | 25 ++++++++----------------- Business/Program.cs | 7 +------ Properties/AssemblyInfo.cs | 4 ++-- Utilities/AppRestart.cs | 2 +- 6 files changed, 24 insertions(+), 39 deletions(-) diff --git a/Business/App.cs b/Business/App.cs index f941a1d..437db28 100644 --- a/Business/App.cs +++ b/Business/App.cs @@ -21,26 +21,29 @@ namespace SystemTrayMenu public App() { AppRestart.BeforeRestarting += Dispose; - SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings; + SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; menus.LoadStarted += menuNotifyIcon.LoadingStart; menus.LoadStopped += menuNotifyIcon.LoadingStop; menuNotifyIcon.Exit += Application.Exit; menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon; - menuNotifyIcon.Click += MenuNotifyIcon_Click; - void MenuNotifyIcon_Click() - { - menus.SwitchOpenClose(true); - } - + menuNotifyIcon.Click += () => menus.SwitchOpenClose(true); menuNotifyIcon.OpenLog += Log.OpenLogFile; menus.MainPreload(); } public void Dispose() { - SystemEvents.DisplaySettingsChanged -= AppRestart.ByDisplaySettings; + SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; menus.Dispose(); menuNotifyIcon.Dispose(); } + + private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) + { + if (!menus.IsOpenCloseStateOpening()) + { + AppRestart.ByDisplaySettings(); + } + } } } \ No newline at end of file diff --git a/Business/KeyboardInput.cs b/Business/KeyboardInput.cs index 2b8dbb8..f72f6c8 100644 --- a/Business/KeyboardInput.cs +++ b/Business/KeyboardInput.cs @@ -53,11 +53,7 @@ namespace SystemTrayMenu.Handler try { hook.RegisterHotKey(); - hook.KeyPressed += Hook_KeyPressed; - void Hook_KeyPressed(object sender, KeyPressedEventArgs e) - { - HotKeyPressed?.Invoke(); - } + hook.KeyPressed += (s, e) => HotKeyPressed?.Invoke(); } catch (InvalidOperationException ex) { diff --git a/Business/Menus.cs b/Business/Menus.cs index bb69dbd..142804d 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -231,12 +231,7 @@ namespace SystemTrayMenu.Business keyboardInput = new KeyboardInput(menus); keyboardInput.RegisterHotKey(); - keyboardInput.HotKeyPressed += KeyboardInput_HotKeyPressed; - void KeyboardInput_HotKeyPressed() - { - SwitchOpenClose(false); - } - + keyboardInput.HotKeyPressed += () => SwitchOpenClose(false); keyboardInput.ClosePressed += MenusFadeOut; keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected; keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly; @@ -259,11 +254,7 @@ namespace SystemTrayMenu.Business } } - waitLeave.LeaveTriggered += LeaveTriggered; - void LeaveTriggered() - { - FadeHalfOrOutIfNeeded(); - } + waitLeave.LeaveTriggered += FadeHalfOrOutIfNeeded; } internal event EventHandlerEmpty LoadStarted; @@ -485,6 +476,11 @@ namespace SystemTrayMenu.Business return menuData; } + internal bool IsOpenCloseStateOpening() + { + return openCloseState == OpenCloseState.Opening; + } + internal void SwitchOpenClose(bool byClick) { waitToOpenMenu.MouseActive = byClick; @@ -657,12 +653,7 @@ namespace SystemTrayMenu.Business } menu.SetTitle(title); - menu.UserClickedOpenFolder += OpenFolderInExplorer; - void OpenFolderInExplorer() - { - OpenFolder(path); - } - + menu.UserClickedOpenFolder += () => OpenFolder(path); menu.Level = menuData.Level; menu.MouseWheel += AdjustMenusSizeAndLocation; menu.MouseLeave += waitLeave.Start; diff --git a/Business/Program.cs b/Business/Program.cs index 9883fc8..bd465b0 100644 --- a/Business/Program.cs +++ b/Business/Program.cs @@ -27,12 +27,7 @@ namespace SystemTrayMenu Config.LoadOrSetByUser(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.ThreadException += ThreadException; - static void ThreadException(object s, ThreadExceptionEventArgs t) - { - AskUserSendError(t.Exception); - } - + Application.ThreadException += (s, t) => AskUserSendError(t.Exception); Scaling.Initialize(); FolderOptions.Initialize(); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 03ecd2c..bf453d2 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.24.0")] -[assembly: AssemblyFileVersion("1.0.24.0")] +[assembly: AssemblyVersion("1.0.24.1")] +[assembly: AssemblyFileVersion("1.0.24.1")] diff --git a/Utilities/AppRestart.cs b/Utilities/AppRestart.cs index b913f72..440a288 100644 --- a/Utilities/AppRestart.cs +++ b/Utilities/AppRestart.cs @@ -24,7 +24,7 @@ namespace SystemTrayMenu.Utilities Restart(GetCurrentMethod()); } - internal static void ByDisplaySettings(object sender, EventArgs e) + internal static void ByDisplaySettings() { Restart(GetCurrentMethod()); }