Skip to content

Commit

Permalink
Clean code and some minor changes to match existing project code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MKKNinetyTwo authored Nov 14, 2024
1 parent a9f44cd commit 1194ef3
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions RetroBar/Utilities/ExplorerMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,47 @@ namespace RetroBar.Utilities
{
public class ExplorerMonitor : IDisposable
{
private bool _ExplorerMonitorIsMonitoring;
private MonitorWindow _explorerMonitor;
private bool _explorerMonitorisMonitoring;
private ExplorerMonitorWindow _explorerMonitorWindow;

public void ExplorerMonitorStart(WindowManager _windowManagerReference)
public void ExplorerMonitorStart(WindowManager windowManagerRef)
{
if(_ExplorerMonitorIsMonitoring) // Prevent multiple monitors.
{
return;
}
else
{
_ExplorerMonitorIsMonitoring = true; // We will set flag to true to prevent multiple monitors.
_explorerMonitor = new MonitorWindow(_windowManagerReference); // Start monitoring.
}
if (_explorerMonitorisMonitoring) { return; } // Prevent multiple monitors.

_explorerMonitorisMonitoring = true;
_explorerMonitorWindow = new ExplorerMonitorWindow(windowManagerRef); // Start monitoring.
}

public void Dispose()
{
if (_explorerMonitor != null){_explorerMonitor?.Dispose();}
_explorerMonitorWindow?.Dispose();
}

// NativeWindow implementation for monitoring
private class MonitorWindow : NativeWindow, IDisposable
private class ExplorerMonitorWindow : NativeWindow, IDisposable
{
private WindowManager _windowManager;
private static readonly int TaskbarCreatedMessage = NativeMethods.RegisterWindowMessage("TaskbarCreated");
private readonly WindowManager _windowManagerRef;
private static readonly int WM_TASKBARCREATEDMESSAGE = NativeMethods.RegisterWindowMessage("TaskbarCreated");

public MonitorWindow(WindowManager _windowManagerReference)
public ExplorerMonitorWindow(WindowManager windowManager)
{
_windowManager = _windowManagerReference;
_windowManagerRef = windowManager;
CreateHandle(new CreateParams());
}

protected override void WndProc(ref Message m)
{
if (m.Msg == TaskbarCreatedMessage)
if (m.Msg == WM_TASKBARCREATEDMESSAGE)
{
try
{
_windowManager.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted.
_windowManagerRef.ReopenTaskbars();
}
catch (Exception ex)
{
Debug.WriteLine($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}");
}
}

// Call the base class to process other messages so we dont accidentally cause crashes or bugs.
base.WndProc(ref m);
}

Expand Down

0 comments on commit 1194ef3

Please sign in to comment.