mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Modules - Remove Name and Icon in favor PluginFeature attribute
This commit is contained in:
parent
730207ccd0
commit
2179c889a3
@ -61,7 +61,6 @@ namespace Artemis.Core.Modules
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="Module{T}" />.
|
||||
/// </summary>
|
||||
@ -79,20 +78,15 @@ namespace Artemis.Core.Modules
|
||||
/// Gets a read only collection of default profile paths
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<(DefaultCategoryName, string)> DefaultProfilePaths => _defaultProfilePaths.AsReadOnly();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The modules display name that's shown in the menu
|
||||
/// </summary>
|
||||
public string? DisplayName { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The modules display icon that's shown in the UI accepts:
|
||||
/// A list of activation requirements
|
||||
/// <para>
|
||||
/// Either set to the name of a Material Icon see (<see href="https://materialdesignicons.com" /> for available
|
||||
/// icons) or set to a path relative to the plugin folder pointing to a .svg file
|
||||
/// If this list is not <see langword="null" /> and not empty <see cref="IsAlwaysAvailable" /> becomes
|
||||
/// <see langword="false" /> and the data of this module is only available to profiles specifically targeting it.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public string? DisplayIcon { get; set; }
|
||||
public abstract List<IModuleActivationRequirement>? ActivationRequirements { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this module is activated. A module can only be active while its <see cref="ActivationRequirements" />
|
||||
@ -114,12 +108,6 @@ namespace Artemis.Core.Modules
|
||||
/// </summary>
|
||||
public bool UpdateDuringActivationOverride { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of activation requirements
|
||||
/// <para>Note: if empty the module is always activated</para>
|
||||
/// </summary>
|
||||
public List<IModuleActivationRequirement> ActivationRequirements { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the activation requirement mode, defaults to <see cref="ActivationRequirementType.Any" />
|
||||
/// </summary>
|
||||
@ -133,7 +121,7 @@ namespace Artemis.Core.Modules
|
||||
/// <see langword="false" />
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public bool IsAlwaysAvailable => ActivationRequirements.Count == 0;
|
||||
public bool IsAlwaysAvailable => ActivationRequirements == null || ActivationRequirements.Count == 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether updating this module is currently allowed
|
||||
@ -181,12 +169,12 @@ namespace Artemis.Core.Modules
|
||||
/// <returns>The evaluated result of the activation requirements</returns>
|
||||
public bool EvaluateActivationRequirements()
|
||||
{
|
||||
if (!ActivationRequirements.Any())
|
||||
if (IsAlwaysAvailable)
|
||||
return true;
|
||||
if (ActivationRequirementMode == ActivationRequirementType.All)
|
||||
return ActivationRequirements.All(r => r.Evaluate());
|
||||
return ActivationRequirements!.All(r => r.Evaluate());
|
||||
if (ActivationRequirementMode == ActivationRequirementType.Any)
|
||||
return ActivationRequirements.Any(r => r.Evaluate());
|
||||
return ActivationRequirements!.Any(r => r.Evaluate());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.LayerEffects;
|
||||
@ -132,6 +131,19 @@ namespace Artemis.Core
|
||||
internal set => SetAndNotify(ref _instance, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representing either a full path pointing to an svg or the markdown icon
|
||||
/// </summary>
|
||||
public string? ResolvedIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Icon == null)
|
||||
return null;
|
||||
return Icon.EndsWith(".svg") ? Plugin.ResolveRelativePath(Icon) : Icon;
|
||||
}
|
||||
}
|
||||
|
||||
internal PluginFeatureEntity Entity { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -152,6 +152,19 @@ namespace Artemis.Core
|
||||
internal set => SetAndNotify(ref _plugin, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string representing either a full path pointing to an svg or the markdown icon
|
||||
/// </summary>
|
||||
public string? ResolvedIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Icon == null)
|
||||
return null;
|
||||
return Icon.EndsWith(".svg") ? Plugin.ResolveRelativePath(Icon) : Icon;
|
||||
}
|
||||
}
|
||||
|
||||
internal string PreferredPluginDirectory => $"{Main.Split(".dll")[0].Replace("/", "").Replace("\\", "")}-{Guid.ToString().Substring(0, 8)}";
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core.LayerEffects;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Modules;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -14,6 +15,8 @@ namespace Artemis.Core
|
||||
IsEnabled = true;
|
||||
}
|
||||
|
||||
public override List<IModuleActivationRequirement>? ActivationRequirements => null;
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
}
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Artemis.Core;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides utilities for UI-related plugin tasks
|
||||
/// </summary>
|
||||
public static class PluginUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Transforms the provided icon so that it is usable by the <see cref="ArtemisIcon" /> control
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin the icon belongs to</param>
|
||||
/// <param name="icon">
|
||||
/// The icon, may be a string representation of a <see cref="PackIconKind" /> or a relative path
|
||||
/// pointing to a .svg file
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static object GetPluginIcon(Plugin plugin, string icon)
|
||||
{
|
||||
if (icon == null)
|
||||
return PackIconKind.QuestionMarkCircle;
|
||||
|
||||
// Icon is provided as a path
|
||||
if (icon.EndsWith(".svg"))
|
||||
{
|
||||
string iconPath = plugin.ResolveRelativePath(icon);
|
||||
if (!File.Exists(iconPath))
|
||||
return PackIconKind.QuestionMarkCircle;
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
// Icon is provided as string to avoid having to reference MaterialDesignThemes
|
||||
bool parsedIcon = Enum.TryParse(icon, true, out PackIconKind iconEnum);
|
||||
if (parsedIcon == false)
|
||||
iconEnum = PackIconKind.QuestionMarkCircle;
|
||||
return iconEnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,7 +142,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
private void PopulateModules()
|
||||
{
|
||||
Modules.Clear();
|
||||
Modules.AddRange(_pluginManagementService.GetFeaturesOfType<Module>().Where(p => p.IsEnabled).OrderBy(m => m.DisplayName));
|
||||
Modules.AddRange(_pluginManagementService.GetFeaturesOfType<Module>().Where(p => p.IsEnabled).OrderBy(m => m.Info.Name));
|
||||
|
||||
if (SelectedModule == null)
|
||||
_dataModelUIService.UpdateModules(MainDataModel);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<ColumnDefinition Width="40"/>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<shared:ArtemisIcon Grid.Column="0" Icon="{Binding Icon}" Width="24" Height="24" />
|
||||
<shared:ArtemisIcon Grid.Column="0" Icon="{Binding Plugin.Info.ResolvedIcon}" Width="24" Height="24" />
|
||||
<TextBlock Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Text="{Binding Plugin.Info.Name}" />
|
||||
</Grid>
|
||||
|
||||
|
||||
@ -1,29 +1,25 @@
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs.Performance
|
||||
{
|
||||
public class PerformanceDebugPluginViewModel : Screen
|
||||
{
|
||||
public Plugin Plugin { get; }
|
||||
public object Icon { get; }
|
||||
|
||||
public PerformanceDebugPluginViewModel(Plugin plugin)
|
||||
{
|
||||
Plugin = plugin;
|
||||
Icon = PluginUtilities.GetPluginIcon(Plugin, Plugin.Info.Icon);
|
||||
}
|
||||
|
||||
public Plugin Plugin { get; }
|
||||
|
||||
public BindableCollection<PerformanceDebugProfilerViewModel> Profilers { get; } = new();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (Profiler pluginProfiler in Plugin.Profilers.Where(p => p.Measurements.Any()))
|
||||
{
|
||||
if (Profilers.All(p => p.Profiler != pluginProfiler))
|
||||
Profilers.Add(new PerformanceDebugProfilerViewModel(pluginProfiler));
|
||||
}
|
||||
|
||||
foreach (PerformanceDebugProfilerViewModel profilerViewModel in Profilers)
|
||||
profilerViewModel.Update();
|
||||
|
||||
@ -29,8 +29,9 @@
|
||||
|
||||
<!-- Icon column -->
|
||||
<shared:ArtemisIcon Grid.Column="0"
|
||||
Icon="{Binding FeatureInfo.Icon}"
|
||||
Icon="{Binding FeatureInfo.ResolvedIcon}"
|
||||
Width="20"
|
||||
Height="20"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted, FallbackValue=Collapsed}" />
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<shared:ArtemisIcon Icon="{Binding Icon}"
|
||||
<shared:ArtemisIcon Icon="{Binding Plugin.Info.ResolvedIcon}"
|
||||
Width="48"
|
||||
Height="48"
|
||||
Margin="0 5 0 0"
|
||||
|
||||
@ -45,8 +45,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
_dialogService = dialogService;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_messageService = messageService;
|
||||
|
||||
Icon = PluginUtilities.GetPluginIcon(Plugin, Plugin.Info.Icon);
|
||||
}
|
||||
|
||||
public Plugin Plugin
|
||||
@ -60,8 +58,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
get => _enabling;
|
||||
set => SetAndNotify(ref _enabling, value);
|
||||
}
|
||||
|
||||
public object Icon { get; set; }
|
||||
|
||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||
public bool CanOpenSettings => IsEnabled && Plugin.ConfigurationDialog != null;
|
||||
|
||||
@ -102,7 +99,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
try
|
||||
{
|
||||
PluginConfigurationViewModel viewModel = (PluginConfigurationViewModel) Plugin.Kernel.Get(configurationViewModel.Type);
|
||||
_windowManager.ShowWindow(new PluginSettingsWindowViewModel(viewModel, Icon));
|
||||
_windowManager.ShowWindow(new PluginSettingsWindowViewModel(viewModel));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -8,10 +8,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
private readonly PluginConfigurationViewModel _configurationViewModel;
|
||||
|
||||
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel, object icon)
|
||||
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel)
|
||||
{
|
||||
_configurationViewModel = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
||||
Icon = icon;
|
||||
Icon = configurationViewModel.Plugin.Info.Icon;
|
||||
}
|
||||
|
||||
public object Icon { get; }
|
||||
|
||||
@ -36,7 +36,7 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
: "any requirement is met";
|
||||
|
||||
Items.Clear();
|
||||
if (Module != null)
|
||||
if (Module?.ActivationRequirements != null)
|
||||
Items.AddRange(Module.ActivationRequirements.Select(_sidebarVmFactory.ModuleActivationRequirementViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,11 +9,8 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
public ProfileModuleViewModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
Name = module.DisplayName;
|
||||
if (module.DisplayIcon != null)
|
||||
Icon = module.DisplayIcon.EndsWith(".svg") ? module.Plugin.ResolveRelativePath(module.DisplayIcon) : module.DisplayIcon;
|
||||
else
|
||||
Icon = PackIconKind.QuestionMark.ToString();
|
||||
Name = module.Info.Name;
|
||||
Icon = module.Info.ResolvedIcon ?? PackIconKind.QuestionMark.ToString();
|
||||
|
||||
Description = module.Info.Description;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user