File tree Expand file tree Collapse file tree 3 files changed +25
-17
lines changed
Plugins/Flow.Launcher.Plugin.Shell Expand file tree Collapse file tree 3 files changed +25
-17
lines changed Original file line number Diff line number Diff line change 22using System . Collections . Concurrent ;
33using System . Collections . Generic ;
44using System . Collections . Specialized ;
5+ using System . ComponentModel ;
56using System . Diagnostics ;
67using System . IO ;
78using System . Linq ;
1011using System . Threading ;
1112using System . Threading . Tasks ;
1213using System . Windows ;
14+ using System . Windows . Input ;
1315using System . Windows . Media ;
1416using CommunityToolkit . Mvvm . DependencyInjection ;
1517using Flow . Launcher . Core ;
3234using JetBrains . Annotations ;
3335using Squirrel ;
3436using Stopwatch = Flow . Launcher . Infrastructure . Stopwatch ;
35- using System . ComponentModel ;
36- using System . Windows . Input ;
3737
3838namespace 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments