Skip to content

Commit 3718ae5

Browse files
committed
Improve code quality & Improve code comments
1 parent edae432 commit 3718ae5

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Collections.Specialized;
5+
using System.ComponentModel;
56
using System.Diagnostics;
67
using System.IO;
78
using System.Linq;
@@ -10,6 +11,7 @@
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using System.Windows;
14+
using System.Windows.Input;
1315
using System.Windows.Media;
1416
using CommunityToolkit.Mvvm.DependencyInjection;
1517
using Flow.Launcher.Core;
@@ -32,8 +34,6 @@
3234
using JetBrains.Annotations;
3335
using Squirrel;
3436
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
35-
using System.ComponentModel;
36-
using System.Windows.Input;
3737

3838
namespace Flow.Launcher
3939
{
@@ -93,18 +93,8 @@ public async void RestartApp()
9393
}
9494

9595
public void ShowMainWindow() => _mainVM.Show();
96-
97-
public void FocusQueryTextBox()
98-
{
99-
Application.Current.Dispatcher.Invoke(new Action(() =>
100-
{
101-
if (Application.Current.MainWindow is MainWindow mw)
102-
{
103-
mw.QueryTextBox.Focus();
104-
Keyboard.Focus(mw.QueryTextBox);
105-
}
106-
}));
107-
}
96+
97+
public void FocusQueryTextBox() => _mainVM.FocusQueryTextBox();
10898

10999
public void HideMainWindow() => _mainVM.Hide();
110100

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,21 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
19261926
Results.AddResults(resultsForUpdates, token, reSelect);
19271927
}
19281928

1929+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
1930+
public void FocusQueryTextBox()
1931+
{
1932+
// When application is exiting, the Application.Current will be null
1933+
Application.Current?.Dispatcher.Invoke(() =>
1934+
{
1935+
// When application is exiting, the Application.Current will be null
1936+
if (Application.Current?.MainWindow is MainWindow window)
1937+
{
1938+
window.QueryTextBox.Focus();
1939+
Keyboard.Focus(window.QueryTextBox);
1940+
}
1941+
});
1942+
}
1943+
19291944
#endregion
19301945

19311946
#region IDisposable

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ private void OnWinRPressed()
382382
// show the main window and set focus to the query box
383383
_ = Task.Run(async () =>
384384
{
385-
await Task.Delay(50); // 💡 키보드 이벤트 처리가 끝난 뒤
386-
Context.API.FocusQueryTextBox();
387-
388385
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
386+
387+
// Win+R is a system-reserved shortcut, and though the plugin intercepts the keyboard event and
388+
// shows the main window, Windows continues to process the Win key and briefly reclaims focus.
389+
// So we need to wait until the keyboard event processing is completed and then set focus
390+
await Task.Delay(50);
391+
Context.API.FocusQueryTextBox();
389392
});
390393
}
391394

0 commit comments

Comments
 (0)