Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reopen race #960

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions RetroBar/Utilities/ExplorerMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ManagedShell.Interop;
using System;
using System.Windows.Forms;
using System.Windows.Threading;

namespace RetroBar.Utilities
{
Expand Down Expand Up @@ -36,14 +37,16 @@ protected override void WndProc(ref Message m)
{
if (m.Msg == WM_TASKBARCREATEDMESSAGE)
{
try
{
_windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted.
}
catch (Exception ex)
{
ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}");
}
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}");
}
});
}

base.WndProc(ref m); // Call the base class to process other messages so we dont accidentally cause crashes or bugs.
Expand Down
9 changes: 7 additions & 2 deletions RetroBar/Utilities/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppBarScreen> _screenState = new List<AppBarScreen>();
Expand Down Expand Up @@ -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)
Expand Down