Improve code quality & Improve code comments

This commit is contained in:
Jack251970 2025-05-22 10:39:09 +08:00
parent edae432852
commit 3718ae5640
3 changed files with 25 additions and 17 deletions

View file

@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -10,6 +11,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
@ -32,8 +34,6 @@ using Flow.Launcher.ViewModel;
using JetBrains.Annotations;
using Squirrel;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
using System.ComponentModel;
using System.Windows.Input;
namespace Flow.Launcher
{
@ -93,18 +93,8 @@ namespace Flow.Launcher
}
public void ShowMainWindow() => _mainVM.Show();
public void FocusQueryTextBox()
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
if (Application.Current.MainWindow is MainWindow mw)
{
mw.QueryTextBox.Focus();
Keyboard.Focus(mw.QueryTextBox);
}
}));
}
public void FocusQueryTextBox() => _mainVM.FocusQueryTextBox();
public void HideMainWindow() => _mainVM.Hide();

View file

@ -1926,6 +1926,21 @@ namespace Flow.Launcher.ViewModel
Results.AddResults(resultsForUpdates, token, reSelect);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
public void FocusQueryTextBox()
{
// When application is exiting, the Application.Current will be null
Application.Current?.Dispatcher.Invoke(() =>
{
// When application is exiting, the Application.Current will be null
if (Application.Current?.MainWindow is MainWindow window)
{
window.QueryTextBox.Focus();
Keyboard.Focus(window.QueryTextBox);
}
});
}
#endregion
#region IDisposable

View file

@ -382,10 +382,13 @@ namespace Flow.Launcher.Plugin.Shell
// show the main window and set focus to the query box
_ = Task.Run(async () =>
{
await Task.Delay(50); // 💡 키보드 이벤트 처리가 끝난 뒤
Context.API.FocusQueryTextBox();
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
// Win+R is a system-reserved shortcut, and though the plugin intercepts the keyboard event and
// shows the main window, Windows continues to process the Win key and briefly reclaims focus.
// So we need to wait until the keyboard event processing is completed and then set focus
await Task.Delay(50);
Context.API.FocusQueryTextBox();
});
}