mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
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
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
public class ProviderSettings
|
|
{
|
|
public bool IsEnabled { get; set; } = true;
|
|
|
|
[JsonIgnore]
|
|
public string ProviderDisplayName { get; set; } = string.Empty;
|
|
|
|
[JsonIgnore]
|
|
public string ProviderId { get; private set; } = string.Empty;
|
|
|
|
[JsonIgnore]
|
|
public bool IsBuiltin { get; private set; }
|
|
|
|
public ProviderSettings(CommandProviderWrapper wrapper)
|
|
{
|
|
Connect(wrapper);
|
|
}
|
|
|
|
[JsonConstructor]
|
|
public ProviderSettings(bool isEnabled)
|
|
{
|
|
IsEnabled = isEnabled;
|
|
}
|
|
|
|
public void Connect(CommandProviderWrapper wrapper)
|
|
{
|
|
ProviderId = wrapper.ProviderId;
|
|
IsBuiltin = wrapper.Extension == null;
|
|
|
|
ProviderDisplayName = wrapper.DisplayName;
|
|
|
|
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!");
|
|
}
|
|
}
|
|
}
|