From 1733883499283990a1ec512a29f056fccadd109d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 20 Nov 2024 00:38:53 -0600 Subject: [PATCH 1/4] Add lock to ReopenTaskbars --- RetroBar/Utilities/WindowManager.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index 811001de..72b157ce 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -9,6 +9,8 @@ namespace RetroBar.Utilities { public class WindowManager : IDisposable { + private static object reopenLock = new object(); + private bool _isSettingDisplays; private int _pendingDisplayEvents; private List _screenState = new List(); @@ -55,8 +57,11 @@ private void Settings_PropertyChanged(object sender, System.ComponentModel.Prope public void ReopenTaskbars() { - closeTaskbars(); - openTaskbars(); + lock (reopenLock) + { + closeTaskbars(); + openTaskbars(); + } } public void NotifyDisplayChange(ScreenSetupReason reason) From 0c7a40daab48318875092a8b645675f7121ef7ad Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 20 Nov 2024 01:36:09 -0600 Subject: [PATCH 2/4] Add taskbar to list before show --- RetroBar/Utilities/WindowManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index 72b157ce..d3ad7a79 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -150,9 +150,8 @@ private void openTaskbar(AppBarScreen screen) { ShellLogger.Debug($"WindowManager: Opening taskbar on screen {screen.DeviceName}"); Taskbar taskbar = new Taskbar(this, _dictionaryManager, _shellManager, _startMenuMonitor, _updater, screen, Settings.Instance.Edge, Settings.Instance.AutoHide ? AppBarMode.AutoHide : AppBarMode.Normal); - taskbar.Show(); - _taskbars.Add(taskbar); + taskbar.Show(); } private bool haveDisplaysChanged() From 7ea7b2b79e1dc7c9f11b9b3905334005584d854a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 20 Nov 2024 22:03:20 -0600 Subject: [PATCH 3/4] Undo previous commit, fix lock --- RetroBar/Utilities/ExplorerMonitor.cs | 5 ++++- RetroBar/Utilities/WindowManager.cs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RetroBar/Utilities/ExplorerMonitor.cs b/RetroBar/Utilities/ExplorerMonitor.cs index bb9ed46c..17183afc 100644 --- a/RetroBar/Utilities/ExplorerMonitor.cs +++ b/RetroBar/Utilities/ExplorerMonitor.cs @@ -2,6 +2,7 @@ using ManagedShell.Interop; using System; using System.Windows.Forms; +using System.Windows.Threading; namespace RetroBar.Utilities { @@ -38,7 +39,9 @@ protected override void WndProc(ref Message m) { try { - _windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. + Dispatcher.CurrentDispatcher.BeginInvoke(() => { + _windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. + }); } catch (Exception ex) { diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index d3ad7a79..72b157ce 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -150,8 +150,9 @@ private void openTaskbar(AppBarScreen screen) { ShellLogger.Debug($"WindowManager: Opening taskbar on screen {screen.DeviceName}"); Taskbar taskbar = new Taskbar(this, _dictionaryManager, _shellManager, _startMenuMonitor, _updater, screen, Settings.Instance.Edge, Settings.Instance.AutoHide ? AppBarMode.AutoHide : AppBarMode.Normal); - _taskbars.Add(taskbar); taskbar.Show(); + + _taskbars.Add(taskbar); } private bool haveDisplaysChanged() From 224791f8df0eac4946f5ab61f27e848e8336ad61 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 21 Nov 2024 00:27:40 -0600 Subject: [PATCH 4/4] Fix error handling --- RetroBar/Utilities/ExplorerMonitor.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/RetroBar/Utilities/ExplorerMonitor.cs b/RetroBar/Utilities/ExplorerMonitor.cs index 17183afc..2d916fd8 100644 --- a/RetroBar/Utilities/ExplorerMonitor.cs +++ b/RetroBar/Utilities/ExplorerMonitor.cs @@ -37,16 +37,16 @@ protected override void WndProc(ref Message m) { if (m.Msg == WM_TASKBARCREATEDMESSAGE) { - try - { - Dispatcher.CurrentDispatcher.BeginInvoke(() => { + Dispatcher.CurrentDispatcher.BeginInvoke(() => { + try + { _windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. - }); - } - catch (Exception ex) - { - ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}"); - } + } + catch (Exception ex) + { + ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}"); + } + }); } base.WndProc(ref m); // Call the base class to process other messages so we dont accidentally cause crashes or bugs.