2021-02-26 19:21:58 +08:00
|
|
|
|
// 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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2021-06-01 15:57:53 +08:00
|
|
|
|
using System.IO;
|
2021-02-26 19:21:58 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class PowerLauncherPluginViewModel : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
private readonly PowerLauncherPluginSettings settings;
|
|
|
|
|
private readonly Func<bool> isDark;
|
|
|
|
|
|
|
|
|
|
public PowerLauncherPluginViewModel(PowerLauncherPluginSettings settings, Func<bool> isDark)
|
|
|
|
|
{
|
|
|
|
|
if (settings == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(settings), "PowerLauncherPluginSettings object is null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.settings = settings;
|
|
|
|
|
this.isDark = isDark;
|
|
|
|
|
foreach (var item in AdditionalOptions)
|
|
|
|
|
{
|
|
|
|
|
item.PropertyChanged += (object sender, PropertyChangedEventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
NotifyPropertyChanged(nameof(AdditionalOptions));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Id { get => settings.Id; }
|
|
|
|
|
|
|
|
|
|
public string Name { get => settings.Name; }
|
|
|
|
|
|
|
|
|
|
public string Description { get => settings.Description; }
|
|
|
|
|
|
|
|
|
|
public string Author { get => settings.Author; }
|
|
|
|
|
|
|
|
|
|
public bool Disabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings.Disabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (settings.Disabled != value)
|
|
|
|
|
{
|
|
|
|
|
settings.Disabled = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
|
|
|
|
NotifyPropertyChanged(nameof(Enabled));
|
|
|
|
|
NotifyPropertyChanged(nameof(DisabledOpacity));
|
2022-07-15 17:26:08 +08:00
|
|
|
|
NotifyPropertyChanged(nameof(IsGlobalAndEnabled));
|
2022-08-24 04:28:41 +08:00
|
|
|
|
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
2021-02-26 19:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Enabled => !Disabled;
|
|
|
|
|
|
|
|
|
|
public double DisabledOpacity => Disabled ? 0.5 : 1;
|
|
|
|
|
|
2022-07-15 17:26:08 +08:00
|
|
|
|
public bool IsGlobalAndEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return IsGlobal && Enabled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 19:21:58 +08:00
|
|
|
|
public bool IsGlobal
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings.IsGlobal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (settings.IsGlobal != value)
|
|
|
|
|
{
|
|
|
|
|
settings.IsGlobal = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
2022-07-15 17:26:08 +08:00
|
|
|
|
NotifyPropertyChanged(nameof(IsGlobalAndEnabled));
|
2022-08-24 04:28:41 +08:00
|
|
|
|
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
2021-02-26 19:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:12:56 +08:00
|
|
|
|
public int WeightBoost
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings.WeightBoost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (settings.WeightBoost != value)
|
|
|
|
|
{
|
|
|
|
|
settings.WeightBoost = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 19:21:58 +08:00
|
|
|
|
public string ActionKeyword
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return settings.ActionKeyword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (settings.ActionKeyword != value)
|
|
|
|
|
{
|
|
|
|
|
settings.ActionKeyword = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
2022-08-24 04:28:41 +08:00
|
|
|
|
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
2021-02-26 19:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<PluginAdditionalOptionViewModel> _additionalOptions;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<PluginAdditionalOptionViewModel> AdditionalOptions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_additionalOptions == null)
|
|
|
|
|
{
|
|
|
|
|
_additionalOptions = settings.AdditionalOptions.Select(x => new PluginAdditionalOptionViewModel(x)).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _additionalOptions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ShowAdditionalOptions
|
|
|
|
|
{
|
|
|
|
|
get => AdditionalOptions.Any();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{Name}. {Description}";
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 15:57:53 +08:00
|
|
|
|
public string IconPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var path = isDark() ? settings.IconPathDark : settings.IconPathLight;
|
|
|
|
|
path = Path.Combine(Directory.GetCurrentDirectory(), @"modules\launcher\Plugins", path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-26 19:21:58 +08:00
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ShowNotAccessibleWarning
|
|
|
|
|
{
|
|
|
|
|
get => !Disabled && !IsGlobal && string.IsNullOrWhiteSpace(ActionKeyword);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 04:28:41 +08:00
|
|
|
|
public bool ShowBadgeOnPluginSettingError
|
2021-02-26 19:21:58 +08:00
|
|
|
|
{
|
2022-08-24 04:28:41 +08:00
|
|
|
|
get => !Disabled && ShowNotAccessibleWarning;
|
2021-02-26 19:21:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|