[PT Run] [Terminal Plugin] Use GetAppListEntires and add scoring (#19148)

* use GetAppListEntires() method

* add scoring
This commit is contained in:
Heiko
2022-07-04 16:19:40 +02:00
committed by GitHub
parent 0da616f917
commit 202abd351b
2 changed files with 15 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Security.Principal;
@@ -14,17 +15,15 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers
{
public class TerminalQuery : ITerminalQuery
{
/// Static list of all Windows Terminal packages. As key we use the app name and in the value we save the AUMID of each package.
/// AUMID = ApplicationUserModelId: This is an identifier id for the app. The syntax is '<PackageFamilyName>!App'.
/// The AUMID of an AppX package will never change. (https://github.com/microsoft/PowerToys/pull/15836#issuecomment-1025204301)
private static readonly IReadOnlyDictionary<string, string> Packages = new Dictionary<string, string>()
{
{ "Microsoft.WindowsTerminal", "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App" },
{ "Microsoft.WindowsTerminalPreview", "Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe!App" },
};
private readonly PackageManager _packageManager;
// Static list of all Windows Terminal packages.
private static ReadOnlyCollection<string> Packages => new List<string>
{
"Microsoft.WindowsTerminal",
"Microsoft.WindowsTerminalPreview",
}.AsReadOnly();
private IEnumerable<TerminalPackage> Terminals => GetTerminals();
public TerminalQuery()
@@ -61,9 +60,11 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers
var user = WindowsIdentity.GetCurrent().User;
var localAppDataPath = Environment.GetEnvironmentVariable("LOCALAPPDATA");
foreach (var p in _packageManager.FindPackagesForUser(user.Value).Where(p => Packages.Keys.Contains(p.Id.Name)))
foreach (var p in _packageManager.FindPackagesForUser(user.Value).Where(p => Packages.Contains(p.Id.Name)))
{
var aumid = Packages[p.Id.Name];
var appListEntries = p.GetAppListEntries();
var aumid = appListEntries.Single().AppUserModelId;
var version = new Version(p.Id.Version.Major, p.Id.Version.Minor, p.Id.Version.Build, p.Id.Version.Revision);
var settingsPath = Path.Combine(localAppDataPath, "Packages", p.Id.FamilyName, "LocalState", "settings.json");
yield return new TerminalPackage(aumid, version, p.DisplayName, settingsPath, p.Logo.LocalPath);

View File

@@ -69,13 +69,15 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
}
// Action keyword only or search query match
if ((!string.IsNullOrWhiteSpace(query.ActionKeyword) && string.IsNullOrWhiteSpace(search)) || StringMatcher.FuzzySearch(search, profile.Name).Success)
int score = StringMatcher.FuzzySearch(search, profile.Name).Score;
if ((!string.IsNullOrWhiteSpace(query.ActionKeyword) && string.IsNullOrWhiteSpace(search)) || score > 0)
{
result.Add(new Result
{
Title = profile.Name,
SubTitle = profile.Terminal.DisplayName,
Icon = () => GetLogo(profile.Terminal),
Score = score,
Action = _ =>
{
Launch(profile.Terminal.AppUserModelId, profile.Name);