Skip to content

Commit e442f36

Browse files
committed
Improve navigation handle check
1 parent b3ff92f commit e442f36

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ public static void OnToggleHotkey(object sender, HotkeyEventArgs args)
154154
{
155155
if (_isInitialized)
156156
{
157-
NavigateDialogPath();
157+
NavigateDialogPath(Win32Helper.GetForegroundWindowHWND());
158158
}
159159
}
160160

161-
private static void NavigateDialogPath(Action action = null)
161+
private static void NavigateDialogPath(HWND dialog, Action action = null)
162162
{
163163
object document = null;
164164
try
@@ -210,20 +210,19 @@ private static void NavigateDialogPath(Action action = null)
210210
return;
211211
}
212212

213-
Log.Debug(ClassName, $"Path: {path}");
214-
JumpToPath(path, action);
213+
JumpToPath(dialog.Value, path, action);
215214
}
216215

217216
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD101:Avoid unsupported async delegates", Justification = "<Pending>")]
218-
public static void JumpToPath(string path, Action action = null)
217+
public static void JumpToPath(nint dialog, string path, Action action = null)
219218
{
220219
if (!CheckPath(path, out var isFile)) return;
221220

222221
var t = new Thread(async () =>
223222
{
224223
// Jump after flow launcher window vanished (after JumpAction returned true)
225224
// and the dialog had been in the foreground.
226-
var timeOut = !SpinWait.SpinUntil(() => GetWindowClassName(PInvoke.GetForegroundWindow()) == DialogWindowClassName, 1000);
225+
var timeOut = !SpinWait.SpinUntil(() => Win32Helper.GetForegroundWindow() == dialog, 1000);
227226
if (timeOut)
228227
{
229228
return;
@@ -233,23 +232,25 @@ public static void JumpToPath(string path, Action action = null)
233232
await _navigationLock.WaitAsync();
234233
try
235234
{
236-
var dialog = Win32Helper.GetForegroundWindowHWND();
235+
var dialogHandle = new HWND(dialog);
237236

238237
bool result;
239238
if (isFile)
240239
{
241-
result = Win32Helper.FileJump(path, dialog);
240+
result = Win32Helper.FileJump(path, dialogHandle);
241+
Log.Debug(ClassName, $"File Jump: {path}");
242242
}
243243
else
244244
{
245-
result = Win32Helper.DirJump(path, dialog);
245+
result = Win32Helper.DirJump(path, dialogHandle);
246+
Log.Debug(ClassName, $"Dir Jump: {path}");
246247
}
247248

248249
if (result)
249250
{
250251
lock (_autoSwitchedDialogsLock)
251252
{
252-
_autoSwitchedDialogs.Add(dialog);
253+
_autoSwitchedDialogs.Add(dialogHandle);
253254
}
254255
}
255256
else
@@ -347,7 +348,7 @@ uint dwmsEventTime
347348
// Show quick switch window after navigating the path
348349
else
349350
{
350-
NavigateDialogPath(() =>
351+
NavigateDialogPath(hwnd, () =>
351352
{
352353
if (_settings.ShowQuickSwitchWindow)
353354
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Flow.Launcher.Plugin.SharedCommands;
2525
using Flow.Launcher.Storage;
2626
using Microsoft.VisualStudio.Threading;
27+
using Windows.Win32;
2728

2829
namespace Flow.Launcher.ViewModel
2930
{
@@ -367,7 +368,7 @@ private void LoadContextMenu()
367368
if (result is QuickSwitchResult quickSwitchResult)
368369
{
369370
Win32Helper.SetForegroundWindow(DialogWindowHandle);
370-
QuickSwitch.JumpToPath(quickSwitchResult.QuickSwitchPath);
371+
QuickSwitch.JumpToPath(Win32Helper.GetForegroundWindow(), quickSwitchResult.QuickSwitchPath);
371372
}
372373
}
373374
}

0 commit comments

Comments
 (0)