Skip to content

Commit b398878

Browse files
committed
Restore to original visibility status & Improve code quality
1 parent 556af5e commit b398878

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class QuickSwitch
2222

2323
public static Action UpdateQuickSwitchWindow { get; set; } = null;
2424

25-
public static Action DestoryQuickSwitchWindow { get; set; } = null;
25+
public static Action ResetQuickSwitchWindow { get; set; } = null;
2626

2727
// The class name of a dialog window
2828
private const string DialogWindowClassName = "#32770";
@@ -209,13 +209,12 @@ uint dwmsEventTime
209209
// If window is dialog window, show quick switch window and navigate path if needed
210210
if (GetWindowClassName(hwnd) == DialogWindowClassName)
211211
{
212-
if (_settings.ShowQuickSwitchWindow)
213-
{
214-
_dialogWindowHandle = hwnd;
215-
ShowQuickSwitchWindow?.Invoke(_dialogWindowHandle.Value);
216-
}
212+
_dialogWindowHandle = hwnd;
213+
ShowQuickSwitchWindow?.Invoke(_dialogWindowHandle.Value);
217214
if (_settings.AutoQuickSwitch)
218215
{
216+
// Showing quick switch window may bring focus
217+
Win32Helper.SetForegroundWindow(hwnd);
219218
NavigateDialogPath();
220219
}
221220
}
@@ -278,7 +277,7 @@ uint dwmsEventTime
278277
if (_dialogWindowHandle != HWND.Null && _dialogWindowHandle == hwnd)
279278
{
280279
_dialogWindowHandle = HWND.Null;
281-
DestoryQuickSwitchWindow?.Invoke();
280+
ResetQuickSwitchWindow?.Invoke();
282281
}
283282
}
284283

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ private void InitializeQuickSwitch()
11621162
{
11631163
QuickSwitch.ShowQuickSwitchWindow = _viewModel.SetupQuickSwitch;
11641164
QuickSwitch.UpdateQuickSwitchWindow = UpdateQuickSwitchPosition;
1165-
QuickSwitch.DestoryQuickSwitchWindow = _viewModel.ResetQuickSwitch;
1165+
QuickSwitch.ResetQuickSwitchWindow = _viewModel.ResetQuickSwitch;
11661166
}
11671167

11681168
#pragma warning disable VSTHRD100 // Avoid async void methods

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,15 @@ public bool ShouldIgnoreHotkeys()
15151515

15161516
public bool IsQuickSwitch { get; private set; }
15171517
public nint DialogWindowHandle { get; private set; } = nint.Zero;
1518+
1519+
private bool PreviousMainWindowVisibilityStatus { get; set; } = true;
15181520

15191521
public void SetupQuickSwitch(nint handle)
15201522
{
1523+
if (!Settings.ShowQuickSwitchWindow) return;
1524+
1525+
PreviousMainWindowVisibilityStatus = MainWindowVisibilityStatus;
1526+
15211527
DialogWindowHandle = handle;
15221528
IsQuickSwitch = true;
15231529
Show();
@@ -1527,7 +1533,15 @@ public void ResetQuickSwitch()
15271533
{
15281534
DialogWindowHandle = nint.Zero;
15291535
IsQuickSwitch = false;
1530-
Hide();
1536+
1537+
if (PreviousMainWindowVisibilityStatus)
1538+
{
1539+
Show();
1540+
}
1541+
else
1542+
{
1543+
Hide();
1544+
}
15311545
}
15321546

15331547
#endregion

0 commit comments

Comments
 (0)