-
-
Notifications
You must be signed in to change notification settings - Fork 455
Add PluginsManager for managing PluginsManifest repo #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- do not allow InstallPlugin method to be called via API - move InstallPlugin functionality to PluginsManager for use exclusively
taooceros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Plugins/Flow.Launcher.Plugin.PluginsManager/Models/PluginsManifest.cs
Outdated
Show resolved
Hide resolved
| return results | ||
| .Where(x => StringMatcher.FuzzySearch(searchName, x.Title).IsSearchPrecisionScoreMet()) | ||
| .Select(x => x) | ||
| .ToList(); |
There was a problem hiding this comment.
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;
})There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Flow.Launcher/Flow.Launcher/ViewModel/ResultsViewModel.cs
Lines 156 to 201 in 920668d
| 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| internal static void Download(string downloadUrl, string toFilePath) | ||
| { | ||
| using var wc = new WebClient { Proxy = Http.WebProxy() }; | ||
|
|
||
| wc.DownloadFile(downloadUrl, toFilePath); | ||
| } |
There was a problem hiding this comment.
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?
taooceros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go!
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