Skip to content

Commit

Permalink
Merge pull request #945 from MKKNinetyTwo/master
Browse files Browse the repository at this point in the history
Implement Explorer.exe monitoring feature.
  • Loading branch information
dremin authored Nov 15, 2024
2 parents 1ea586d + e5363b2 commit f52ab9c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
58 changes: 58 additions & 0 deletions RetroBar/Utilities/ExplorerMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using ManagedShell.Common.Logging;
using ManagedShell.Interop;
using System;
using System.Windows.Forms;

namespace RetroBar.Utilities
{
public class ExplorerMonitor : IDisposable
{
private ExplorerMonitorWindow _explorerMonitorWindow;

public void ExplorerMonitorStart(WindowManager windowManagerRef)
{
if (_explorerMonitorWindow != null) { return; } // Prevent multiple monitors.

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

public void Dispose()
{
_explorerMonitorWindow?.Dispose();
}

private class ExplorerMonitorWindow : NativeWindow, IDisposable
{
private readonly WindowManager _windowManagerRef;
private static readonly int WM_TASKBARCREATEDMESSAGE = NativeMethods.RegisterWindowMessage("TaskbarCreated");

public ExplorerMonitorWindow(WindowManager windowManagerRef)
{
_windowManagerRef = windowManagerRef;
CreateHandle(new CreateParams());
}

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}");
}
}

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

public void Dispose()
{
DestroyHandle();
}
}
}
}
7 changes: 6 additions & 1 deletion RetroBar/Utilities/WindowManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ManagedShell;
using ManagedShell;
using ManagedShell.AppBar;
using ManagedShell.Common.Logging;
using System;
Expand All @@ -18,12 +18,16 @@ public class WindowManager : IDisposable
private readonly ShellManager _shellManager;
private readonly Updater _updater;

private readonly ExplorerMonitor _explorerMonitor = new();

public WindowManager(ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater)
{
_shellManager = shellManager;
_startMenuMonitor = startMenuMonitor;
_updater = updater;

_explorerMonitor.ExplorerMonitorStart(this);

_shellManager.ExplorerHelper.HideExplorerTaskbar = true;

openTaskbars();
Expand Down Expand Up @@ -183,6 +187,7 @@ private void resetScreenCache()

public void Dispose()
{
_explorerMonitor?.Dispose();
_shellManager.ExplorerHelper.HideExplorerTaskbar = false;
Settings.Instance.PropertyChanged -= Settings_PropertyChanged;
}
Expand Down

0 comments on commit f52ab9c

Please sign in to comment.