Skip to content

Commit 69d8b12

Browse files
committed
Add process name check for Windows Explorer
1 parent 08f9b68 commit 69d8b12

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/Models/WindowsExplorer.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,37 @@ internal class WindowsExplorer : IQuickSwitchExplorer
2121
public bool CheckExplorerWindow(HWND foreground)
2222
{
2323
var isExplorer = false;
24-
lock (_lastExplorerViewLock)
24+
// Is it from Explorer?
25+
var processName = Win32Helper.GetProcessNameFromHwnd(foreground);
26+
if (processName.ToLower() == "explorer.exe")
2527
{
2628
EnumerateShellWindows((shellWindow) =>
2729
{
2830
try
2931
{
30-
if (shellWindow is not IWebBrowser2 explorer)
31-
{
32-
return;
33-
}
32+
if (shellWindow is not IWebBrowser2 explorer) return true;
33+
34+
if (explorer.HWND != foreground.Value) return true;
3435

35-
if (explorer.HWND != foreground.Value)
36+
lock (_lastExplorerViewLock)
3637
{
37-
return;
38+
_lastExplorerView = explorer;
3839
}
39-
40-
_lastExplorerView = explorer;
4140
isExplorer = true;
41+
return false;
4242
}
4343
catch (COMException)
4444
{
4545
// Ignored
4646
}
47+
48+
return true;
4749
});
4850
}
4951
return isExplorer;
5052
}
5153

52-
private static unsafe void EnumerateShellWindows(Action<object> action)
54+
private static unsafe void EnumerateShellWindows(Func<object, bool> action)
5355
{
5456
// Create an instance of ShellWindows
5557
var clsidShellWindows = new Guid("9BA05972-F6A8-11CF-A442-00A0C90A8F39"); // ShellWindowsClass
@@ -70,7 +72,10 @@ private static unsafe void EnumerateShellWindows(Action<object> action)
7072
var count = shellWindows.Count;
7173
for (var i = 0; i < count; i++)
7274
{
73-
action(shellWindows.Item(i));
75+
if (!action(shellWindows.Item(i)))
76+
{
77+
return;
78+
}
7479
}
7580
}
7681

0 commit comments

Comments
 (0)