CmdPal: Fix SUI crash ; Allow extensions to be disabled (#38040)

Both `TopLevelCommandItemWrapper` and `TopLevelViewModel` were really the same thing. The latter was from an earlier prototype, and the former is a more correct, safer abstraction. We really should have only ever used the former, but alas, we only used it for the SUI, and it piggy-backed off the latter, and that meant the latter's bugs became the former's.


tldr: I made the icon access safe in the SUI. 

And while I was doing this, because we now have a cleaner VM abstraction here in the host, we can actually cleanly disable extensions, because the `CommandProviderWrapper` knows which `ViewModel`s it made. 

Closes https://github.com/zadjii-msft/PowerToys/issues/426
Closes https://github.com/zadjii-msft/PowerToys/issues/478
Closes https://github.com/zadjii-msft/PowerToys/issues/577
This commit is contained in:
Mike Griese
2025-03-20 15:36:10 -05:00
committed by GitHub
parent 57cbcc2c3e
commit 14919dff10
34 changed files with 590 additions and 528 deletions

View File

@@ -10,23 +10,14 @@ public class ProviderSettings
{
public bool IsEnabled { get; set; } = true;
[JsonIgnore]
public string PackageFamilyName { get; set; } = string.Empty;
[JsonIgnore]
public string Id { get; set; } = string.Empty;
[JsonIgnore]
public string ProviderDisplayName { get; set; } = string.Empty;
// Originally, I wanted to do:
// public string ProviderId => $"{PackageFamilyName}/{ProviderDisplayName}";
// but I think that's actually a bad idea, because the Display Name can be localized.
[JsonIgnore]
public string ProviderId => $"{PackageFamilyName}/{Id}";
public string ProviderId { get; private set; } = string.Empty;
[JsonIgnore]
public bool IsBuiltin => string.IsNullOrEmpty(PackageFamilyName);
public bool IsBuiltin { get; private set; }
public ProviderSettings(CommandProviderWrapper wrapper)
{
@@ -41,10 +32,12 @@ public class ProviderSettings
public void Connect(CommandProviderWrapper wrapper)
{
PackageFamilyName = wrapper.Extension?.PackageFamilyName ?? string.Empty;
Id = wrapper.DisplayName;
ProviderId = wrapper.ProviderId;
IsBuiltin = wrapper.Extension == null;
ProviderDisplayName = wrapper.DisplayName;
if (ProviderId == "/")
if (string.IsNullOrEmpty(ProviderId))
{
throw new InvalidDataException("Did you add a built-in command and forget to set the Id? Make sure you do that!");
}