Skip to content

Commit 0e02416

Browse files
committed
Improve auto quick switch
1 parent a74ad6d commit 0e02416

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static void OnToggleHotkey(object sender, HotkeyEventArgs args)
150150
}
151151
}
152152

153-
private static void NavigateDialogPath()
153+
private static void NavigateDialogPath(Action action = null)
154154
{
155155
object document = null;
156156
try
@@ -199,10 +199,10 @@ private static void NavigateDialogPath()
199199
return;
200200
}
201201

202-
JumpToPath(path);
202+
JumpToPath(path, action);
203203
}
204204

205-
public static bool JumpToPath(string path)
205+
public static bool JumpToPath(string path, Action action = null)
206206
{
207207
if (!CheckPath(path, out var isFile)) return false;
208208

@@ -225,6 +225,9 @@ public static bool JumpToPath(string path)
225225
{
226226
Win32Helper.DirJump(path, Win32Helper.GetForegroundWindow());
227227
}
228+
229+
// Invoke action if provided
230+
action?.Invoke();
228231
});
229232
t.Start();
230233
return true;
@@ -272,30 +275,38 @@ private static void ForegroundChangeCallback(
272275
uint dwmsEventTime
273276
)
274277
{
275-
// File dialog window is foreground
278+
// File dialog window
276279
if (GetWindowClassName(hwnd) == DialogWindowClassName)
277280
{
278281
lock (_dialogWindowHandleLock)
279282
{
280283
_dialogWindowHandle = hwnd;
281284
}
282285

286+
// Navigate to path
287+
if (_settings.AutoQuickSwitch)
288+
{
289+
Win32Helper.SetForegroundWindow(hwnd);
290+
NavigateDialogPath(() =>
291+
{
292+
// Show quick switch window after path is navigated
293+
if (_settings.ShowQuickSwitchWindow)
294+
{
295+
ShowQuickSwitchWindow?.Invoke(_dialogWindowHandle.Value);
296+
_dragMoveTimer?.Start();
297+
}
298+
});
299+
return;
300+
}
301+
283302
// Show quick switch window
284303
if (_settings.ShowQuickSwitchWindow)
285304
{
286305
ShowQuickSwitchWindow?.Invoke(_dialogWindowHandle.Value);
287306
_dragMoveTimer?.Start();
288307
}
289-
290-
// Navigate path if needed
291-
if (_settings.AutoQuickSwitch)
292-
{
293-
// Showing quick switch window may bring focus
294-
Win32Helper.SetForegroundWindow(hwnd);
295-
NavigateDialogPath();
296-
}
297308
}
298-
// Quick switch window is foreground
309+
// Quick switch window
299310
else if (hwnd == _mainWindowHandle)
300311
{
301312
// Nothing to do

0 commit comments

Comments
 (0)