mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
code quality
This commit is contained in:
parent
50f5e850dd
commit
545c4208d9
1 changed files with 29 additions and 43 deletions
|
|
@ -40,9 +40,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
private Query _lastQuery;
|
private Query _lastQuery;
|
||||||
private bool _previousIsHomeQuery;
|
private bool _previousIsHomeQuery;
|
||||||
private string _queryTextBeforeLeaveResults;
|
private string _queryTextBeforeLeaveResults;
|
||||||
|
private string _ignoredQueryText; // Used to ignore query text change when switching between context menu and query results
|
||||||
private string
|
|
||||||
_ignoredQueryText; // Used to ignore query text change when switching between context menu and query results
|
|
||||||
|
|
||||||
private readonly FlowLauncherJsonStorage<History> _historyStorage;
|
private readonly FlowLauncherJsonStorage<History> _historyStorage;
|
||||||
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
|
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
|
||||||
|
|
@ -156,7 +154,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
_userSelectedRecordStorage = new FlowLauncherJsonStorage<UserSelectedRecord>();
|
_userSelectedRecordStorage = new FlowLauncherJsonStorage<UserSelectedRecord>();
|
||||||
_topMostRecord = new FlowLauncherJsonStorageTopMostRecord();
|
_topMostRecord = new FlowLauncherJsonStorageTopMostRecord();
|
||||||
|
|
||||||
|
|
||||||
_history = _historyStorage.Load();
|
_history = _historyStorage.Load();
|
||||||
_userSelectedRecord = _userSelectedRecordStorage.Load();
|
_userSelectedRecord = _userSelectedRecordStorage.Load();
|
||||||
|
|
||||||
|
|
@ -244,16 +241,14 @@ namespace Flow.Launcher.ViewModel
|
||||||
// Indicate if to clear existing results so to show only ones from plugins with action keywords
|
// Indicate if to clear existing results so to show only ones from plugins with action keywords
|
||||||
var query = item.Query;
|
var query = item.Query;
|
||||||
var currentIsHomeQuery = query.IsHomeQuery;
|
var currentIsHomeQuery = query.IsHomeQuery;
|
||||||
var shouldClearExistingResults =
|
var shouldClearExistingResults = ShouldClearExistingResultsForQuery(query, currentIsHomeQuery);
|
||||||
ShouldClearExistingResultsForQuery(query, currentIsHomeQuery);
|
|
||||||
_lastQuery = item.Query;
|
_lastQuery = item.Query;
|
||||||
_previousIsHomeQuery = currentIsHomeQuery;
|
_previousIsHomeQuery = currentIsHomeQuery;
|
||||||
|
|
||||||
// If the queue already has the item, we need to pass the shouldClearExistingResults flag
|
// If the queue already has the item, we need to pass the shouldClearExistingResults flag
|
||||||
if (queue.TryGetValue(item.ID, out var existingItem))
|
if (queue.TryGetValue(item.ID, out var existingItem))
|
||||||
{
|
{
|
||||||
item.ShouldClearExistingResults = shouldClearExistingResults ||
|
item.ShouldClearExistingResults = shouldClearExistingResults || existingItem.ShouldClearExistingResults;
|
||||||
existingItem.ShouldClearExistingResults;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -324,7 +319,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
App.API.LogDebug(ClassName, $"Update results for plugin <{pair.Metadata.Name}>");
|
App.API.LogDebug(ClassName, $"Update results for plugin <{pair.Metadata.Name}>");
|
||||||
|
|
||||||
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, pair.Metadata, e.Query,
|
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, pair.Metadata, e.Query,
|
||||||
token)))
|
token)))
|
||||||
{
|
{
|
||||||
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
|
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
|
||||||
}
|
}
|
||||||
|
|
@ -427,8 +422,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
if (result is DialogJumpResult dialogJumpResult)
|
if (result is DialogJumpResult dialogJumpResult)
|
||||||
{
|
{
|
||||||
Win32Helper.SetForegroundWindow(DialogWindowHandle);
|
Win32Helper.SetForegroundWindow(DialogWindowHandle);
|
||||||
_ = Task.Run(() =>
|
_ = Task.Run(() => DialogJump.JumpToPathAsync(DialogWindowHandle, dialogJumpResult.DialogJumpPath));
|
||||||
DialogJump.JumpToPathAsync(DialogWindowHandle, dialogJumpResult.DialogJumpPath));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,8 +547,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, bool isDialogJump,
|
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, bool isDialogJump, CancellationToken token = default)
|
||||||
CancellationToken token = default)
|
|
||||||
{
|
{
|
||||||
var resultsCopy = new List<Result>();
|
var resultsCopy = new List<Result>();
|
||||||
|
|
||||||
|
|
@ -578,7 +571,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
resultsCopy.Add(resultCopy);
|
resultsCopy.Add(resultCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultsCopy;
|
return resultsCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,9 +620,8 @@ namespace Flow.Launcher.ViewModel
|
||||||
var historyItems = _history.GetHistoryItems(Settings);
|
var historyItems = _history.GetHistoryItems(Settings);
|
||||||
if (QueryResultsSelected() // Results selected
|
if (QueryResultsSelected() // Results selected
|
||||||
&& string.IsNullOrEmpty(QueryText) // No input
|
&& string.IsNullOrEmpty(QueryText) // No input
|
||||||
&& Results.Visibility !=
|
&& Results.Visibility != Visibility.Visible // No items in result list, e.g. when home page is off and no query text is entered, therefore the view is collapsed.
|
||||||
Visibility.Visible // No items in result list, e.g. when home page is off and no query text is entered, therefore the view is collapsed.
|
&& historyItems.Count > 0)
|
||||||
&& historyItems.Count > 0) // Have history items
|
|
||||||
{
|
{
|
||||||
lastHistoryIndex = 1;
|
lastHistoryIndex = 1;
|
||||||
ReverseHistory();
|
ReverseHistory();
|
||||||
|
|
@ -702,7 +693,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
public bool GameModeStatus { get; set; } = false;
|
public bool GameModeStatus { get; set; } = false;
|
||||||
|
|
||||||
private string _queryText;
|
private string _queryText;
|
||||||
|
|
||||||
public string QueryText
|
public string QueryText
|
||||||
{
|
{
|
||||||
get => _queryText;
|
get => _queryText;
|
||||||
|
|
@ -864,8 +854,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
|
|
||||||
// If we are returning from history and we have not set select item yet,
|
// If we are returning from history and we have not set select item yet,
|
||||||
// we need to clear the preview selected item
|
// we need to clear the preview selected item
|
||||||
if (isReturningFromHistory && _selectedItemFromQueryResults.HasValue &&
|
if (isReturningFromHistory && _selectedItemFromQueryResults.HasValue && (!_selectedItemFromQueryResults.Value))
|
||||||
(!_selectedItemFromQueryResults.Value))
|
|
||||||
{
|
{
|
||||||
PreviewSelectedItem = null;
|
PreviewSelectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
@ -883,7 +872,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
ContextMenu.Visibility = Visibility.Visible;
|
ContextMenu.Visibility = Visibility.Visible;
|
||||||
History.Visibility = Visibility.Collapsed;
|
History.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
_queryTextBeforeLeaveResults = QueryText;
|
_queryTextBeforeLeaveResults = QueryText;
|
||||||
|
|
||||||
// Because of Fody's optimization
|
// Because of Fody's optimization
|
||||||
|
|
@ -899,8 +887,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
{
|
{
|
||||||
// If we are returning from query results and we have not set select item yet,
|
// If we are returning from query results and we have not set select item yet,
|
||||||
// we need to clear the preview selected item
|
// we need to clear the preview selected item
|
||||||
if (isReturningFromQueryResults && _selectedItemFromQueryResults.HasValue &&
|
if (isReturningFromQueryResults && _selectedItemFromQueryResults.HasValue && _selectedItemFromQueryResults.Value)
|
||||||
_selectedItemFromQueryResults.Value)
|
|
||||||
{
|
{
|
||||||
PreviewSelectedItem = null;
|
PreviewSelectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
@ -910,9 +897,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public Visibility ShowCustomizedPreview
|
public Visibility ShowCustomizedPreview
|
||||||
=> InternalPreviewVisible && PreviewSelectedItem?.Result.PreviewPanel != null
|
=> InternalPreviewVisible && PreviewSelectedItem?.Result.PreviewPanel != null ? Visibility.Visible : Visibility.Collapsed;
|
||||||
? Visibility.Visible
|
|
||||||
: Visibility.Collapsed;
|
|
||||||
|
|
||||||
public UserControl CustomizedPreviewControl
|
public UserControl CustomizedPreviewControl
|
||||||
=> ShowCustomizedPreview == Visibility.Visible ? PreviewSelectedItem?.Result.PreviewPanel.Value : null;
|
=> ShowCustomizedPreview == Visibility.Visible ? PreviewSelectedItem?.Result.PreviewPanel.Value : null;
|
||||||
|
|
@ -933,7 +918,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
public double SearchIconOpacity { get; set; } = 1;
|
public double SearchIconOpacity { get; set; } = 1;
|
||||||
|
|
||||||
private string _placeholderText;
|
private string _placeholderText;
|
||||||
|
|
||||||
public string PlaceholderText
|
public string PlaceholderText
|
||||||
{
|
{
|
||||||
get => string.IsNullOrEmpty(_placeholderText) ? Localize.queryTextBoxPlaceholder() : _placeholderText;
|
get => string.IsNullOrEmpty(_placeholderText) ? Localize.queryTextBoxPlaceholder() : _placeholderText;
|
||||||
|
|
@ -1032,7 +1016,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
private bool? _selectedItemFromQueryResults;
|
private bool? _selectedItemFromQueryResults;
|
||||||
|
|
||||||
private ResultViewModel _previewSelectedItem;
|
private ResultViewModel _previewSelectedItem;
|
||||||
|
|
||||||
public ResultViewModel PreviewSelectedItem
|
public ResultViewModel PreviewSelectedItem
|
||||||
{
|
{
|
||||||
get => _previewSelectedItem;
|
get => _previewSelectedItem;
|
||||||
|
|
@ -1053,8 +1036,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
if (ResultAreaColumn == ResultAreaColumnPreviewHidden)
|
if (ResultAreaColumn == ResultAreaColumnPreviewHidden)
|
||||||
return false;
|
return false;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
throw new NotImplementedException(
|
throw new NotImplementedException("ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value");
|
||||||
"ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value");
|
|
||||||
#else
|
#else
|
||||||
App.API.LogError(ClassName, "ResultAreaColumnPreviewHidden/ResultAreaColumnPreviewShown int value not implemented", "InternalPreviewVisible");
|
App.API.LogError(ClassName, "ResultAreaColumnPreviewHidden/ResultAreaColumnPreviewShown int value not implemented", "InternalPreviewVisible");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1189,7 +1171,6 @@ namespace Flow.Launcher.ViewModel
|
||||||
await CloseExternalPreviewAsync();
|
await CloseExternalPreviewAsync();
|
||||||
ShowInternalPreview();
|
ShowInternalPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case false
|
case false
|
||||||
when InternalPreviewVisible:
|
when InternalPreviewVisible:
|
||||||
|
|
@ -1278,7 +1259,10 @@ namespace Flow.Launcher.ViewModel
|
||||||
List<Result> results;
|
List<Result> results;
|
||||||
if (selected.PluginID == null) // SelectedItem from history in home page.
|
if (selected.PluginID == null) // SelectedItem from history in home page.
|
||||||
{
|
{
|
||||||
results = new() { ContextMenuTopMost(selected) };
|
results = new()
|
||||||
|
{
|
||||||
|
ContextMenuTopMost(selected)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1290,15 +1274,16 @@ namespace Flow.Launcher.ViewModel
|
||||||
if (!string.IsNullOrEmpty(query))
|
if (!string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
var filtered = results.Select(x => x.Clone()).Where
|
var filtered = results.Select(x => x.Clone()).Where
|
||||||
(r =>
|
(
|
||||||
{
|
r =>
|
||||||
var match = App.API.FuzzySearch(query, r.Title);
|
{
|
||||||
if (!match.IsSearchPrecisionScoreMet())
|
var match = App.API.FuzzySearch(query, r.Title);
|
||||||
{
|
if (!match.IsSearchPrecisionScoreMet())
|
||||||
match = App.API.FuzzySearch(query, r.SubTitle);
|
{
|
||||||
}
|
match = App.API.FuzzySearch(query, r.SubTitle);
|
||||||
|
}
|
||||||
|
|
||||||
if (!match.IsSearchPrecisionScoreMet()) return false;
|
if (!match.IsSearchPrecisionScoreMet()) return false;
|
||||||
|
|
||||||
r.Score = match.Score;
|
r.Score = match.Score;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1325,9 +1310,10 @@ namespace Flow.Launcher.ViewModel
|
||||||
if (!string.IsNullOrEmpty(query))
|
if (!string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
var filtered = results.Where
|
var filtered = results.Where
|
||||||
(r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
(
|
||||||
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
||||||
).ToList();
|
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
||||||
|
).ToList();
|
||||||
History.AddResults(filtered, id);
|
History.AddResults(filtered, id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue