[BUG] Do not restart if DisplayChange was due to STM open (#223), version 1.0.24.1

This commit is contained in:
Markus Hofknecht 2021-10-25 18:55:34 +02:00
parent ae34aded47
commit 9189b0629d
6 changed files with 24 additions and 39 deletions

View file

@ -21,26 +21,29 @@ namespace SystemTrayMenu
public App() public App()
{ {
AppRestart.BeforeRestarting += Dispose; AppRestart.BeforeRestarting += Dispose;
SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
menus.LoadStarted += menuNotifyIcon.LoadingStart; menus.LoadStarted += menuNotifyIcon.LoadingStart;
menus.LoadStopped += menuNotifyIcon.LoadingStop; menus.LoadStopped += menuNotifyIcon.LoadingStop;
menuNotifyIcon.Exit += Application.Exit; menuNotifyIcon.Exit += Application.Exit;
menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon; menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon;
menuNotifyIcon.Click += MenuNotifyIcon_Click; menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
void MenuNotifyIcon_Click()
{
menus.SwitchOpenClose(true);
}
menuNotifyIcon.OpenLog += Log.OpenLogFile; menuNotifyIcon.OpenLog += Log.OpenLogFile;
menus.MainPreload(); menus.MainPreload();
} }
public void Dispose() public void Dispose()
{ {
SystemEvents.DisplaySettingsChanged -= AppRestart.ByDisplaySettings; SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
menus.Dispose(); menus.Dispose();
menuNotifyIcon.Dispose(); menuNotifyIcon.Dispose();
} }
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
if (!menus.IsOpenCloseStateOpening())
{
AppRestart.ByDisplaySettings();
}
}
} }
} }

View file

@ -53,11 +53,7 @@ namespace SystemTrayMenu.Handler
try try
{ {
hook.RegisterHotKey(); hook.RegisterHotKey();
hook.KeyPressed += Hook_KeyPressed; hook.KeyPressed += (s, e) => HotKeyPressed?.Invoke();
void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
HotKeyPressed?.Invoke();
}
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {

View file

@ -231,12 +231,7 @@ namespace SystemTrayMenu.Business
keyboardInput = new KeyboardInput(menus); keyboardInput = new KeyboardInput(menus);
keyboardInput.RegisterHotKey(); keyboardInput.RegisterHotKey();
keyboardInput.HotKeyPressed += KeyboardInput_HotKeyPressed; keyboardInput.HotKeyPressed += () => SwitchOpenClose(false);
void KeyboardInput_HotKeyPressed()
{
SwitchOpenClose(false);
}
keyboardInput.ClosePressed += MenusFadeOut; keyboardInput.ClosePressed += MenusFadeOut;
keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected; keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected;
keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly; keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly;
@ -259,11 +254,7 @@ namespace SystemTrayMenu.Business
} }
} }
waitLeave.LeaveTriggered += LeaveTriggered; waitLeave.LeaveTriggered += FadeHalfOrOutIfNeeded;
void LeaveTriggered()
{
FadeHalfOrOutIfNeeded();
}
} }
internal event EventHandlerEmpty LoadStarted; internal event EventHandlerEmpty LoadStarted;
@ -485,6 +476,11 @@ namespace SystemTrayMenu.Business
return menuData; return menuData;
} }
internal bool IsOpenCloseStateOpening()
{
return openCloseState == OpenCloseState.Opening;
}
internal void SwitchOpenClose(bool byClick) internal void SwitchOpenClose(bool byClick)
{ {
waitToOpenMenu.MouseActive = byClick; waitToOpenMenu.MouseActive = byClick;
@ -657,12 +653,7 @@ namespace SystemTrayMenu.Business
} }
menu.SetTitle(title); menu.SetTitle(title);
menu.UserClickedOpenFolder += OpenFolderInExplorer; menu.UserClickedOpenFolder += () => OpenFolder(path);
void OpenFolderInExplorer()
{
OpenFolder(path);
}
menu.Level = menuData.Level; menu.Level = menuData.Level;
menu.MouseWheel += AdjustMenusSizeAndLocation; menu.MouseWheel += AdjustMenusSizeAndLocation;
menu.MouseLeave += waitLeave.Start; menu.MouseLeave += waitLeave.Start;

View file

@ -27,12 +27,7 @@ namespace SystemTrayMenu
Config.LoadOrSetByUser(); Config.LoadOrSetByUser();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += ThreadException; Application.ThreadException += (s, t) => AskUserSendError(t.Exception);
static void ThreadException(object s, ThreadExceptionEventArgs t)
{
AskUserSendError(t.Exception);
}
Scaling.Initialize(); Scaling.Initialize();
FolderOptions.Initialize(); FolderOptions.Initialize();

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.24.0")] [assembly: AssemblyVersion("1.0.24.1")]
[assembly: AssemblyFileVersion("1.0.24.0")] [assembly: AssemblyFileVersion("1.0.24.1")]

View file

@ -24,7 +24,7 @@ namespace SystemTrayMenu.Utilities
Restart(GetCurrentMethod()); Restart(GetCurrentMethod());
} }
internal static void ByDisplaySettings(object sender, EventArgs e) internal static void ByDisplaySettings()
{ {
Restart(GetCurrentMethod()); Restart(GetCurrentMethod());
} }