Skip to content

Conversation

@jjw24
Copy link
Member

@jjw24 jjw24 commented Dec 6, 2020

This PR adds the new plugin PluginsManager to manage installing, and uninstalling plugins.

New PR will be added for the update plugins feature & context menu

@jjw24 jjw24 added the enhancement New feature or request label Dec 6, 2020
@jjw24 jjw24 self-assigned this Dec 6, 2020
@jjw24 jjw24 marked this pull request as draft December 6, 2020 09:00
@jjw24 jjw24 marked this pull request as ready for review December 10, 2020 12:09
Copy link
Member

@taooceros taooceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Comment on lines 84 to 87
return results
.Where(x => StringMatcher.FuzzySearch(searchName, x.Title).IsSearchPrecisionScoreMet())
.Select(x => x)
.ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the score to order it?
Like

.Where(x=>{
x.Score = StringMatcher.FuzzySearch(searchName,x.Title));
return x.Score>0;
})

Copy link
Member Author

@jjw24 jjw24 Dec 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

score > 0 will return a lot of results that have a score, that's why we are using IsSearchPrecisionScoreMet(), it matches the precision level that the user selected, default is 50, so only results with a score equal or higher will return.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you are not right here. The score property will make every raw score lower than search precision become 0, so no worry for more results. The one you suggested that can be lower than search precision is called rawScore.

Copy link
Member Author

@jjw24 jjw24 Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you are right about the score property.

I dont see a benefit of doing x.score > 0 as oppose to just calling the function which has the logic embedded without having to hardcode any numbers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean by changing x.score to the score from the fuzzy search can make the result list sort since the view model will sort it by its score.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give me a code snippet please, not sure what you mean

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean by setting the score of each Result can help the result list to sort it based on the score.
Check out this

private List<ResultViewModel> NewResults(List<Result> newRawResults, string resultId)
{
var results = Results.ToList();
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings)).ToList();
var oldResults = results.Where(r => r.Result.PluginID == resultId).ToList();
// Find the same results in A (old results) and B (new newResults)
var sameResults = oldResults
.Where(t1 => newResults.Any(x => x.Result.Equals(t1.Result)))
.ToList();
// remove result of relative complement of B in A
foreach (var result in oldResults.Except(sameResults))
{
results.Remove(result);
}
// update result with B's score and index position
foreach (var sameResult in sameResults)
{
int oldIndex = results.IndexOf(sameResult);
int oldScore = results[oldIndex].Result.Score;
var newResult = newResults[newResults.IndexOf(sameResult)];
int newScore = newResult.Result.Score;
if (newScore != oldScore)
{
var oldResult = results[oldIndex];
oldResult.Result.Score = newScore;
oldResult.Result.OriginQuery = newResult.Result.OriginQuery;
results.RemoveAt(oldIndex);
int newIndex = InsertIndexOf(newScore, results);
results.Insert(newIndex, oldResult);
}
}
// insert result in relative complement of A in B
foreach (var result in newResults.Except(sameResults))
{
int newIndex = InsertIndexOf(result.Result.Score, results);
results.Insert(newIndex, result);
}
return results;
}

Although I don't believe this part of codes are clear enough, but it do provides the ability to sorts the results to display on the results list view based on their score.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh gotcha, I forgot to set the score for each of the result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted. good catch, thank you

Comment on lines 92 to 111
var results = new List<Result>();

pluginsManifest
.UserPlugins
.ForEach(x => results.Add(
new Result
{
Title = $"{x.Name} by {x.Author}",
SubTitle = x.Description,
IcoPath = icoPath,
Action = e =>
{
Application.Current.MainWindow.Hide();
InstallOrUpdate(x);

return true;
}
}));

return Search(results, searchName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I do think it will be more elegent to simply use the Select method to get the resultlist but this is fine, too.

var unzippedFolderCount = Directory.GetDirectories(unzippedParentFolderPath).Length;
var unzippedFilesCount = Directory.GetFiles(unzippedParentFolderPath).Length;

// addjust path depending on how the plugin is zipped up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addjust
is this typo hhh?

Comment on lines 61 to 66
internal static void Download(string downloadUrl, string toFilePath)
{
using var wc = new WebClient { Proxy = Http.WebProxy() };

wc.DownloadFile(downloadUrl, toFilePath);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have referenced to Flow.Launcher.Infruastructure, why not simply use the one lies in Http.cs?

@jjw24 jjw24 requested a review from taooceros December 14, 2020 03:15
@jjw24 jjw24 requested review from taooceros and removed request for taooceros December 14, 2020 10:07
Copy link
Member

@taooceros taooceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@taooceros taooceros merged commit 0eef6c2 into dev Dec 14, 2020
@taooceros taooceros deleted the add_pluginsmanager branch December 14, 2020 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants