1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Plugins - Add JSON property to disable auto-enabling features

Setup wizard - Play intro animation at the end (and no where else)
This commit is contained in:
SpoinkyNL 2020-12-12 10:57:09 +01:00
parent c6181ea823
commit 8e8258506b
8 changed files with 879 additions and 83 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Newtonsoft.Json;
namespace Artemis.Core
@ -9,6 +10,7 @@ namespace Artemis.Core
[JsonObject(MemberSerialization.OptIn)]
public class PluginInfo : CorePropertyChanged
{
private bool _autoEnableFeatures = true;
private string? _description;
private Guid _guid;
private string? _icon;
@ -83,6 +85,17 @@ namespace Artemis.Core
internal set => SetAndNotify(ref _main, value);
}
/// <summary>
/// Gets or sets a boolean indicating whether this plugin should automatically enable all its features when it is first loaded
/// </summary>
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool AutoEnableFeatures
{
get => _autoEnableFeatures;
set => SetAndNotify(ref _autoEnableFeatures, value);
}
/// <summary>
/// Gets the plugin this info is associated with
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,6 @@ namespace Artemis.Core.Services
ArtemisSurface surfaceConfig = _surfaceService.ActiveSurface;
_logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.EntityId);
PlayIntroAnimation();
OnInitialized();
}
@ -111,12 +110,8 @@ namespace Artemis.Core.Services
FrameRendered?.Invoke(this, e);
}
private void PlayIntroAnimation()
public void PlayIntroAnimation()
{
// The intro is cool and all, but sometimes you just wanna see what you're working on straight away ^^
if (Debugger.IsAttached)
return;
IntroAnimation intro = new IntroAnimation(_logger, _profileService, _surfaceService);
// Draw a white overlay over the device

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that initializes the Core and manages the render loop
/// A service that initializes the Core and manages the render loop
/// </summary>
public interface ICoreService : IArtemisService, IDisposable
{
@ -33,6 +33,11 @@ namespace Artemis.Core.Services
/// </summary>
void Initialize();
/// <summary>
/// Plays the into animation profile defined in <c>Resources/intro-profile.json</c>
/// </summary>
void PlayIntroAnimation();
/// <summary>
/// Occurs the core has finished initializing
/// </summary>

View File

@ -185,6 +185,7 @@ namespace Artemis.Core.Services
// Load the plugin assemblies into the plugin context
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
{
try
{
Plugin plugin = LoadPlugin(subDirectory);
@ -195,6 +196,7 @@ namespace Artemis.Core.Services
{
_logger.Warning(new ArtemisPluginException("Failed to load plugin", e), "Plugin exception");
}
}
LoadingPlugins = false;
}
@ -308,6 +310,7 @@ namespace Artemis.Core.Services
// Create instances of each feature and add them to the plugin
// Construction should be simple and not contain any logic so failure at this point means the entire plugin fails
foreach (Type featureType in featureTypes)
{
try
{
plugin.Kernel.Bind(featureType).ToSelf().InSingletonScope();
@ -319,15 +322,17 @@ namespace Artemis.Core.Services
// Load the enabled state and if not found, default to true
instance.Entity = plugin.Entity.Features.FirstOrDefault(i => i.Type == featureType.FullName) ??
new PluginFeatureEntity {IsEnabled = true, Type = featureType.FullName!};
new PluginFeatureEntity {IsEnabled = plugin.Info.AutoEnableFeatures, Type = featureType.FullName!};
}
catch (Exception e)
{
throw new ArtemisPluginException(plugin, "Failed to instantiate feature", e);
}
}
// Activate plugins after they are all loaded
foreach (PluginFeature pluginFeature in plugin.Features.Where(i => i.Entity.IsEnabled))
{
try
{
EnablePluginFeature(pluginFeature, false, !ignorePluginLock);
@ -336,6 +341,7 @@ namespace Artemis.Core.Services
{
// ignored, logged in EnablePluginFeature
}
}
if (saveState)
{
@ -477,8 +483,10 @@ namespace Artemis.Core.Services
private void SavePlugin(Plugin plugin)
{
foreach (PluginFeature pluginFeature in plugin.Features)
{
if (plugin.Entity.Features.All(i => i.Type != pluginFeature.GetType().FullName))
plugin.Entity.Features.Add(pluginFeature.Entity);
}
_pluginRepository.SavePlugin(plugin.Entity);
}

View File

@ -207,7 +207,9 @@ namespace Artemis.Core.Services
public void AutoArrange(ArtemisSurface? artemisSurface = null)
{
artemisSurface ??= ActiveSurface;
if (!artemisSurface.Devices.Any())
return;
SurfaceArrangement surfaceArrangement = SurfaceArrangement.GetDefaultArrangement();
surfaceArrangement.Arrange(artemisSurface);
UpdateSurfaceConfiguration(artemisSurface, true);

View File

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DeviceProviders;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
@ -24,7 +25,13 @@ namespace Artemis.UI.Screens.SetupWizard.Steps
protected override void OnActivate()
{
Items.Clear();
Items.AddRange(_pluginManagementService.GetFeaturesOfType<DeviceProvider>().Select(d => _settingsVmFactory.CreatePluginFeatureViewModel(d)));
// _pluginManagementService.GetFeaturesOfType<>() will only give us enabled features so lets get all of them this way
IEnumerable<DeviceProvider> features = _pluginManagementService.GetAllPlugins()
.SelectMany(p => p.Features.Where(f => f is DeviceProvider))
.Cast<DeviceProvider>()
.OrderBy(d => d.GetType().Name);
Items.AddRange(features.Select(d => _settingsVmFactory.CreatePluginFeatureViewModel(d)));
base.OnActivate();
}

View File

@ -1,10 +1,18 @@
using System.Windows.Navigation;
using Artemis.Core.Services;
using Stylet;
namespace Artemis.UI.Screens.SetupWizard.Steps
{
public class FinishStepViewModel : Screen
{
private readonly ICoreService _coreService;
public FinishStepViewModel(ICoreService coreService)
{
_coreService = coreService;
}
public void OpenHyperlink(object sender, RequestNavigateEventArgs e)
{
Core.Utilities.OpenUrl(e.Uri.AbsoluteUri);
@ -14,5 +22,11 @@ namespace Artemis.UI.Screens.SetupWizard.Steps
{
((SetupWizardViewModel) Parent).SkipOrFinishWizard();
}
protected override void OnActivate()
{
_coreService.PlayIntroAnimation();
base.OnActivate();
}
}
}