mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08:00
[PowerToys Run] Windows Terminal plugin: Improve query speed (#15836)
* Change code to query aumid * update comment * update aumid on package update * fix tetx position * Write AUMID as static values in code * code style
This commit is contained in:
parent
314425e32e
commit
2a34cf740b
@ -4,25 +4,25 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using Windows.Foundation;
|
||||
using Windows.Management.Deployment;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers
|
||||
{
|
||||
public class TerminalQuery : ITerminalQuery
|
||||
{
|
||||
private readonly PackageManager _packageManager;
|
||||
|
||||
private static ReadOnlyCollection<string> Packages => new List<string>
|
||||
/// 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.WindowsTerminalPreview",
|
||||
}.AsReadOnly();
|
||||
{ "Microsoft.WindowsTerminal", "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App" },
|
||||
{ "Microsoft.WindowsTerminalPreview", "Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe!App" },
|
||||
};
|
||||
|
||||
private readonly PackageManager _packageManager;
|
||||
|
||||
private IEnumerable<TerminalPackage> Terminals => GetTerminals();
|
||||
|
||||
@ -54,19 +54,13 @@ 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.Contains(p.Id.Name)))
|
||||
foreach (var p in _packageManager.FindPackagesForUser(user.Value).Where(p => Packages.Keys.Contains(p.Id.Name)))
|
||||
{
|
||||
var appListEntries = p.GetAppListEntriesAsync();
|
||||
while (appListEntries.Status != AsyncStatus.Completed)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
var aumid = appListEntries.GetResults().Single().AppUserModelId;
|
||||
var aumid = Packages[p.Id.Name];
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user