From 202abd351b3c1206c6daa4b43ccbcb70b0d5f9f2 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Mon, 4 Jul 2022 16:19:40 +0200 Subject: [PATCH] [PT Run] [Terminal Plugin] Use GetAppListEntires and add scoring (#19148) * use GetAppListEntires() method * add scoring --- .../Helpers/TerminalQuery.cs | 23 ++++++++++--------- .../Main.cs | 4 +++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalQuery.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalQuery.cs index fb28697bf5..34d6afeb1b 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalQuery.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalQuery.cs @@ -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 '!App'. - /// The AUMID of an AppX package will never change. (https://github.com/microsoft/PowerToys/pull/15836#issuecomment-1025204301) - private static readonly IReadOnlyDictionary Packages = new Dictionary() - { - { "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 Packages => new List + { + "Microsoft.WindowsTerminal", + "Microsoft.WindowsTerminalPreview", + }.AsReadOnly(); + private IEnumerable 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); diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs index 25a605a8d0..e5b0c14346 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs @@ -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);