Skip to content

Commit 2d34f1f

Browse files
committed
Add IQuickSwitchExplorerWindow interface
1 parent a05e9f8 commit 2d34f1f

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ internal class WindowsDialog : IQuickSwitchDialog
1919

2020
private const string WindowsDialogClassName = "#32770";
2121

22-
public string Name => "Windows";
23-
2422
public bool CheckDialogWindow(IntPtr hwnd)
2523
{
2624
// Has it been checked?

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

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ namespace Flow.Launcher.Infrastructure.QuickSwitch.Models
1212
/// </summary>
1313
public class WindowsExplorer : IQuickSwitchExplorer
1414
{
15-
private static readonly string ClassName = nameof(WindowsExplorer);
15+
public IQuickSwitchExplorerWindow ExplorerWindow { get; private set; }
1616

17-
private static IWebBrowser2 _lastExplorerView = null;
18-
private static readonly object _lastExplorerViewLock = new();
17+
private static readonly string ClassName = nameof(WindowsExplorer);
1918

2019
public bool CheckExplorerWindow(IntPtr foreground)
2120
{
@@ -32,10 +31,7 @@ public bool CheckExplorerWindow(IntPtr foreground)
3231

3332
if (explorer.HWND != foreground) return true;
3433

35-
lock (_lastExplorerViewLock)
36-
{
37-
_lastExplorerView = explorer;
38-
}
34+
ExplorerWindow = new WindowsExplorerWindow(foreground, explorer);
3935
isExplorer = true;
4036
return false;
4137
}
@@ -78,6 +74,50 @@ private static unsafe void EnumerateShellWindows(Func<object, bool> action)
7874
}
7975
}
8076

77+
public void RemoveExplorerWindow()
78+
{
79+
ExplorerWindow = null;
80+
}
81+
82+
public void Dispose()
83+
{
84+
ExplorerWindow?.Dispose();
85+
}
86+
}
87+
88+
public class WindowsExplorerWindow : IQuickSwitchExplorerWindow
89+
{
90+
public IntPtr Handle { get; }
91+
92+
private static readonly object _lastExplorerViewLock = new();
93+
private static IWebBrowser2 _lastExplorerView = null;
94+
95+
internal WindowsExplorerWindow(IntPtr handle, IWebBrowser2 explorerView)
96+
{
97+
Handle = handle;
98+
_lastExplorerView = explorerView;
99+
}
100+
101+
public void Dispose()
102+
{
103+
// Release ComObjects
104+
try
105+
{
106+
lock (_lastExplorerViewLock)
107+
{
108+
if (_lastExplorerView != null)
109+
{
110+
Marshal.ReleaseComObject(_lastExplorerView);
111+
_lastExplorerView = null;
112+
}
113+
}
114+
}
115+
catch (COMException)
116+
{
117+
_lastExplorerView = null;
118+
}
119+
}
120+
81121
public string GetExplorerPath()
82122
{
83123
if (_lastExplorerView == null) return null;
@@ -134,33 +174,5 @@ public string GetExplorerPath()
134174

135175
return path;
136176
}
137-
138-
public void RemoveExplorerWindow()
139-
{
140-
lock (_lastExplorerViewLock)
141-
{
142-
_lastExplorerView = null;
143-
}
144-
}
145-
146-
public void Dispose()
147-
{
148-
// Release ComObjects
149-
try
150-
{
151-
lock (_lastExplorerViewLock)
152-
{
153-
if (_lastExplorerView != null)
154-
{
155-
Marshal.ReleaseComObject(_lastExplorerView);
156-
_lastExplorerView = null;
157-
}
158-
}
159-
}
160-
catch (COMException)
161-
{
162-
_lastExplorerView = null;
163-
}
164-
}
165177
}
166178
}

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private static bool RefreshLastExplorer()
259259

260260
public static string GetActiveExplorerPath()
261261
{
262-
return RefreshLastExplorer() ? _lastExplorer.GetExplorerPath() : string.Empty;
262+
return RefreshLastExplorer() ? _lastExplorer.ExplorerWindow?.GetExplorerPath() : string.Empty;
263263
}
264264

265265
#endregion
@@ -610,7 +610,7 @@ private static async Task<bool> NavigateDialogPathAsync(HWND hwnd, bool auto = f
610610
string path;
611611
lock (_lastExplorerLock)
612612
{
613-
path = _lastExplorer?.GetExplorerPath();
613+
path = _lastExplorer?.ExplorerWindow?.GetExplorerPath();
614614
}
615615
if (string.IsNullOrEmpty(path)) return false;
616616

Flow.Launcher.Plugin/Interfaces/IQuickSwitchExplorer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Flow.Launcher.Plugins
77
/// </summary>
88
public interface IQuickSwitchExplorer : IDisposable
99
{
10+
IQuickSwitchExplorerWindow ExplorerWindow { get; }
11+
1012
/// <summary>
1113
/// Check if the foreground window is a Windows Explorer instance.
1214
/// </summary>
@@ -22,11 +24,12 @@ public interface IQuickSwitchExplorer : IDisposable
2224
///
2325
/// </summary>
2426
void RemoveExplorerWindow();
27+
}
28+
29+
public interface IQuickSwitchExplorerWindow : IDisposable
30+
{
31+
IntPtr Handle { get; }
2532

26-
/// <summary>
27-
///
28-
/// </summary>
29-
/// <returns></returns>
3033
string GetExplorerPath();
3134
}
3235
}

0 commit comments

Comments
 (0)