Plugins - Simplified and streamlined the way plugins provide VMs

Plugins - Added dependency injection to all plugin VMs
Plugin settings - Allow injecting plugin settings into any class defined in the plugin assembly
This commit is contained in:
Robert committed 2020-08-21 11:14:53 +02:00
1 parent aa3c3d6b95
commit c71faba2c9
29 files changed
+349 -165

No files matched your search

@@ -1,5 +1,4 @@
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Devices.DMX.ViewModels;
@@ -13,19 +12,15 @@ namespace Artemis.Plugins.Devices.DMX
public DMXDeviceProvider(IRgbService rgbService) : base(RGB.NET.Devices.DMX.DMXDeviceProvider.Instance)
{
_rgbService = rgbService;
HasConfigurationViewModel = true;
}
public override void EnablePlugin()
{
ConfigurationDialog = new PluginConfigurationDialog<DMXConfigurationViewModel>();
// TODO: Load from configuration
// RGB.NET.Devices.DMX.DMXDeviceProvider.Instance.AddDeviceDefinition();
_rgbService.AddDeviceProvider(RgbDeviceProvider);
}
public override PluginConfigurationViewModel GetConfigurationViewModel()
{
return new DMXConfigurationViewModel(this);
}
}
}
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Devices.Debug.Settings;
@@ -24,22 +22,26 @@ namespace Artemis.Plugins.Devices.Debug
_rgbService = rgbService;
}
public override void EnablePlugin()
{
HasConfigurationViewModel = true;
ConfigurationDialog = new PluginConfigurationDialog<DebugConfigurationViewModel>();
PathHelper.ResolvingAbsolutePath += PathHelperOnResolvingAbsolutePath;
var definitions = _settings.GetSetting<List<DeviceDefinition>>("DeviceDefinitions");
var definitions = _settings.GetSetting("DeviceDefinitions", new List<DeviceDefinition>());
if (definitions.Value == null)
definitions.Value = new List<DeviceDefinition>();
foreach (var deviceDefinition in definitions.Value)
foreach (var deviceDefinition in definitions.Value)
RGB.NET.Devices.Debug.DebugDeviceProvider.Instance.AddFakeDeviceDefinition(deviceDefinition.Layout, deviceDefinition.ImageLayout);
_rgbService.AddDeviceProvider(RgbDeviceProvider);
}
public override void DisablePlugin()
{
// TODO: Remove the device provider from the surface
}
private void PathHelperOnResolvingAbsolutePath(object sender, ResolvePathEventArgs e)
{
if (sender is DebugRGBDevice debugRgbDevice)
@@ -49,19 +51,7 @@ namespace Artemis.Plugins.Devices.Debug
var rootDirectory = debugRgbDevice.LayoutPath.Split("\\Layouts")[0];
e.FinalPath = Path.Combine(rootDirectory, e.RelativePath);
}
var test =debugRgbDevice.LayoutPath;
}
}
public override void DisablePlugin()
{
// TODO: Remove the device provider from the surface
}
public override PluginConfigurationViewModel GetConfigurationViewModel()
{
return new DebugConfigurationViewModel(this, _settings);
}
}
}
@@ -10,11 +10,11 @@ namespace Artemis.Plugins.Devices.Debug.ViewModels
{
public class DebugConfigurationViewModel : PluginConfigurationViewModel
{
private PluginSetting<List<DeviceDefinition>> _definitions;
private readonly PluginSetting<List<DeviceDefinition>> _definitions;
public DebugConfigurationViewModel(Plugin plugin, PluginSettings settings) : base(plugin)
{
_definitions = settings.GetSetting<List<DeviceDefinition>>("DeviceDefinitions");
_definitions = settings.GetSetting("DeviceDefinitions", new List<DeviceDefinition>());
Definitions = new BindableCollection<DeviceDefinition>(_definitions.Value);
}
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Devices.WS281X.Settings;
@@ -23,10 +22,9 @@ namespace Artemis.Plugins.Devices.WS281X
_rgbService = rgbService;
}
public override void EnablePlugin()
{
HasConfigurationViewModel = true;
ConfigurationDialog = new PluginConfigurationDialog<WS281XConfigurationViewModel>();
var definitions = _settings.GetSetting<List<DeviceDefinition>>("DeviceDefinitions");
if (definitions.Value == null)
@@ -54,10 +52,5 @@ namespace Artemis.Plugins.Devices.WS281X
{
// TODO: Remove the device provider from the surface
}
public override PluginConfigurationViewModel GetConfigurationViewModel()
{
return new WS281XConfigurationViewModel(this, _settings);
}
}
}
@@ -1,4 +1,4 @@
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.LayerEffect;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Plugins.LayerEffects.Filter.ViewModels;
using SkiaSharp;
@@ -9,12 +9,7 @@ namespace Artemis.Plugins.LayerEffects.Filter
{
public override void EnableLayerEffect()
{
HasConfigurationViewModel = true;
}
public override EffectConfigurationViewModel GetConfigurationViewModel()
{
return new ColorMatrixConfigurationViewModel(this);
ConfigurationDialog = new LayerEffectConfigurationDialog<ColorMatrixConfigurationViewModel>();
}
public override void DisableLayerEffect()
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Abstract.ViewModels;
using Artemis.Core.Plugins.Modules;
using Artemis.Plugins.Modules.General.DataModel;
using Artemis.Plugins.Modules.General.DataModel.Windows;
@@ -18,6 +17,7 @@ namespace Artemis.Plugins.Modules.General
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsDataModel = true;
ModuleTabs = new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(1), CurrentTimeUTC = DateTime.UtcNow.AddDays(1)});
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(2), CurrentTimeUTC = DateTime.UtcNow.AddDays(2)});
@@ -46,11 +46,6 @@ namespace Artemis.Plugins.Modules.General
base.Update(deltaTime);
}
public override IEnumerable<ModuleTab> GetModuleTabs()
{
return new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
}
#region Open windows
public void UpdateCurrentWindow()