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>
|
/// <summary>
|
||||||
/// For internal use only, please use <see cref="Module{T}" />.
|
/// For internal use only, please use <see cref="Module{T}" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -81,18 +80,13 @@ namespace Artemis.Core.Modules
|
|||||||
public IReadOnlyCollection<(DefaultCategoryName, string)> DefaultProfilePaths => _defaultProfilePaths.AsReadOnly();
|
public IReadOnlyCollection<(DefaultCategoryName, string)> DefaultProfilePaths => _defaultProfilePaths.AsReadOnly();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The modules display name that's shown in the menu
|
/// A list of activation requirements
|
||||||
/// </summary>
|
|
||||||
public string? DisplayName { get; protected set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The modules display icon that's shown in the UI accepts:
|
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Either set to the name of a Material Icon see (<see href="https://materialdesignicons.com" /> for available
|
/// If this list is not <see langword="null" /> and not empty <see cref="IsAlwaysAvailable" /> becomes
|
||||||
/// icons) or set to a path relative to the plugin folder pointing to a .svg file
|
/// <see langword="false" /> and the data of this module is only available to profiles specifically targeting it.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? DisplayIcon { get; set; }
|
public abstract List<IModuleActivationRequirement>? ActivationRequirements { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether this module is activated. A module can only be active while its <see cref="ActivationRequirements" />
|
/// 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>
|
/// </summary>
|
||||||
public bool UpdateDuringActivationOverride { get; protected set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the activation requirement mode, defaults to <see cref="ActivationRequirementType.Any" />
|
/// Gets or sets the activation requirement mode, defaults to <see cref="ActivationRequirementType.Any" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -133,7 +121,7 @@ namespace Artemis.Core.Modules
|
|||||||
/// <see langword="false" />
|
/// <see langword="false" />
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsAlwaysAvailable => ActivationRequirements.Count == 0;
|
public bool IsAlwaysAvailable => ActivationRequirements == null || ActivationRequirements.Count == 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether updating this module is currently allowed
|
/// 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>
|
/// <returns>The evaluated result of the activation requirements</returns>
|
||||||
public bool EvaluateActivationRequirements()
|
public bool EvaluateActivationRequirements()
|
||||||
{
|
{
|
||||||
if (!ActivationRequirements.Any())
|
if (IsAlwaysAvailable)
|
||||||
return true;
|
return true;
|
||||||
if (ActivationRequirementMode == ActivationRequirementType.All)
|
if (ActivationRequirementMode == ActivationRequirementType.All)
|
||||||
return ActivationRequirements.All(r => r.Evaluate());
|
return ActivationRequirements!.All(r => r.Evaluate());
|
||||||
if (ActivationRequirementMode == ActivationRequirementType.Any)
|
if (ActivationRequirementMode == ActivationRequirementType.Any)
|
||||||
return ActivationRequirements.Any(r => r.Evaluate());
|
return ActivationRequirements!.Any(r => r.Evaluate());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.DataModelExpansions;
|
|
||||||
using Artemis.Core.DeviceProviders;
|
using Artemis.Core.DeviceProviders;
|
||||||
using Artemis.Core.LayerBrushes;
|
using Artemis.Core.LayerBrushes;
|
||||||
using Artemis.Core.LayerEffects;
|
using Artemis.Core.LayerEffects;
|
||||||
@ -132,6 +131,19 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _instance, value);
|
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; }
|
internal PluginFeatureEntity Entity { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -152,6 +152,19 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _plugin, value);
|
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)}";
|
internal string PreferredPluginDirectory => $"{Main.Split(".dll")[0].Replace("/", "").Replace("\\", "")}-{Guid.ToString().Substring(0, 8)}";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Artemis.Core.LayerEffects;
|
using System.Collections.Generic;
|
||||||
|
using Artemis.Core.LayerEffects;
|
||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -14,6 +15,8 @@ namespace Artemis.Core
|
|||||||
IsEnabled = true;
|
IsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override List<IModuleActivationRequirement>? ActivationRequirements => null;
|
||||||
|
|
||||||
public override void Enable()
|
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()
|
private void PopulateModules()
|
||||||
{
|
{
|
||||||
Modules.Clear();
|
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)
|
if (SelectedModule == null)
|
||||||
_dataModelUIService.UpdateModules(MainDataModel);
|
_dataModelUIService.UpdateModules(MainDataModel);
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<ColumnDefinition Width="40"/>
|
<ColumnDefinition Width="40"/>
|
||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
</Grid.ColumnDefinitions>
|
</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}" />
|
<TextBlock Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Text="{Binding Plugin.Info.Name}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,25 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Shared;
|
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs.Performance
|
namespace Artemis.UI.Screens.Settings.Debug.Tabs.Performance
|
||||||
{
|
{
|
||||||
public class PerformanceDebugPluginViewModel : Screen
|
public class PerformanceDebugPluginViewModel : Screen
|
||||||
{
|
{
|
||||||
public Plugin Plugin { get; }
|
|
||||||
public object Icon { get; }
|
|
||||||
|
|
||||||
public PerformanceDebugPluginViewModel(Plugin plugin)
|
public PerformanceDebugPluginViewModel(Plugin plugin)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
Icon = PluginUtilities.GetPluginIcon(Plugin, Plugin.Info.Icon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Plugin Plugin { get; }
|
||||||
|
|
||||||
public BindableCollection<PerformanceDebugProfilerViewModel> Profilers { get; } = new();
|
public BindableCollection<PerformanceDebugProfilerViewModel> Profilers { get; } = new();
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
foreach (Profiler pluginProfiler in Plugin.Profilers.Where(p => p.Measurements.Any()))
|
foreach (Profiler pluginProfiler in Plugin.Profilers.Where(p => p.Measurements.Any()))
|
||||||
{
|
|
||||||
if (Profilers.All(p => p.Profiler != pluginProfiler))
|
if (Profilers.All(p => p.Profiler != pluginProfiler))
|
||||||
Profilers.Add(new PerformanceDebugProfilerViewModel(pluginProfiler));
|
Profilers.Add(new PerformanceDebugProfilerViewModel(pluginProfiler));
|
||||||
}
|
|
||||||
|
|
||||||
foreach (PerformanceDebugProfilerViewModel profilerViewModel in Profilers)
|
foreach (PerformanceDebugProfilerViewModel profilerViewModel in Profilers)
|
||||||
profilerViewModel.Update();
|
profilerViewModel.Update();
|
||||||
|
|||||||
@ -29,8 +29,9 @@
|
|||||||
|
|
||||||
<!-- Icon column -->
|
<!-- Icon column -->
|
||||||
<shared:ArtemisIcon Grid.Column="0"
|
<shared:ArtemisIcon Grid.Column="0"
|
||||||
Icon="{Binding FeatureInfo.Icon}"
|
Icon="{Binding FeatureInfo.ResolvedIcon}"
|
||||||
Width="20"
|
Width="20"
|
||||||
|
Height="20"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted, FallbackValue=Collapsed}" />
|
Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted, FallbackValue=Collapsed}" />
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<shared:ArtemisIcon Icon="{Binding Icon}"
|
<shared:ArtemisIcon Icon="{Binding Plugin.Info.ResolvedIcon}"
|
||||||
Width="48"
|
Width="48"
|
||||||
Height="48"
|
Height="48"
|
||||||
Margin="0 5 0 0"
|
Margin="0 5 0 0"
|
||||||
|
|||||||
@ -45,8 +45,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
_pluginManagementService = pluginManagementService;
|
_pluginManagementService = pluginManagementService;
|
||||||
_messageService = messageService;
|
_messageService = messageService;
|
||||||
|
|
||||||
Icon = PluginUtilities.GetPluginIcon(Plugin, Plugin.Info.Icon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin Plugin
|
public Plugin Plugin
|
||||||
@ -61,7 +59,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
set => SetAndNotify(ref _enabling, value);
|
set => SetAndNotify(ref _enabling, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Icon { get; set; }
|
|
||||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||||
public bool CanOpenSettings => IsEnabled && Plugin.ConfigurationDialog != null;
|
public bool CanOpenSettings => IsEnabled && Plugin.ConfigurationDialog != null;
|
||||||
|
|
||||||
@ -102,7 +99,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PluginConfigurationViewModel viewModel = (PluginConfigurationViewModel) Plugin.Kernel.Get(configurationViewModel.Type);
|
PluginConfigurationViewModel viewModel = (PluginConfigurationViewModel) Plugin.Kernel.Get(configurationViewModel.Type);
|
||||||
_windowManager.ShowWindow(new PluginSettingsWindowViewModel(viewModel, Icon));
|
_windowManager.ShowWindow(new PluginSettingsWindowViewModel(viewModel));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,10 +8,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
{
|
{
|
||||||
private readonly PluginConfigurationViewModel _configurationViewModel;
|
private readonly PluginConfigurationViewModel _configurationViewModel;
|
||||||
|
|
||||||
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel, object icon)
|
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel)
|
||||||
{
|
{
|
||||||
_configurationViewModel = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
_configurationViewModel = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
||||||
Icon = icon;
|
Icon = configurationViewModel.Plugin.Info.Icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Icon { get; }
|
public object Icon { get; }
|
||||||
|
|||||||
@ -36,7 +36,7 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
|||||||
: "any requirement is met";
|
: "any requirement is met";
|
||||||
|
|
||||||
Items.Clear();
|
Items.Clear();
|
||||||
if (Module != null)
|
if (Module?.ActivationRequirements != null)
|
||||||
Items.AddRange(Module.ActivationRequirements.Select(_sidebarVmFactory.ModuleActivationRequirementViewModel));
|
Items.AddRange(Module.ActivationRequirements.Select(_sidebarVmFactory.ModuleActivationRequirementViewModel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,11 +9,8 @@ namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
|||||||
public ProfileModuleViewModel(Module module)
|
public ProfileModuleViewModel(Module module)
|
||||||
{
|
{
|
||||||
Module = module;
|
Module = module;
|
||||||
Name = module.DisplayName;
|
Name = module.Info.Name;
|
||||||
if (module.DisplayIcon != null)
|
Icon = module.Info.ResolvedIcon ?? PackIconKind.QuestionMark.ToString();
|
||||||
Icon = module.DisplayIcon.EndsWith(".svg") ? module.Plugin.ResolveRelativePath(module.DisplayIcon) : module.DisplayIcon;
|
|
||||||
else
|
|
||||||
Icon = PackIconKind.QuestionMark.ToString();
|
|
||||||
|
|
||||||
Description = module.Info.Description;
|
Description = module.Info.Description;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user