From c846d63acfd418b666eec99cba353b1ab7fa7193 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 11 Nov 2019 22:12:36 +0100 Subject: [PATCH] Added some of the architecture for the profile editor --- src/Artemis.Core/Plugins/Abstract/Module.cs | 7 ++-- .../Plugins/Abstract/ModuleViewModel.cs | 4 +- src/Artemis.Core/Services/PluginService.cs | 20 +++++++-- .../GeneralModule.cs | 8 ++-- .../ViewModels/GeneralViewModel.cs | 2 +- src/Artemis.UI/App.xaml | 9 +++- src/Artemis.UI/Artemis.UI.csproj | 17 ++++++-- .../Factories/ModuleViewModelFactory.cs | 10 +++++ src/Artemis.UI/Ninject/UiModule.cs | 7 +++- .../ProfileEditor/ProfileEditorViewModel.cs | 16 +++++++ .../ViewModels/Interfaces/IEditorViewModel.cs | 7 ---- .../ViewModels/Interfaces/IHomeViewModel.cs | 7 ---- .../Interfaces/ISettingsViewModel.cs | 6 --- .../ViewModels/Screens/DebugViewModel.cs | 5 ++- .../ViewModels/Screens/HomeViewModel.cs | 2 +- .../ViewModels/Screens/ModuleRootViewModel.cs | 21 ++++++++++ .../ViewModels/Screens/RootViewModel.cs | 11 +++-- .../ViewModels/Screens/SettingsViewModel.cs | 2 +- .../ViewModels/Screens/SplashViewModel.cs | 8 +--- .../Screens/SurfaceEditorViewModel.cs | 2 +- .../ProfileEditor/ProfileEditorView.xaml | 14 +++++++ src/Artemis.UI/Views/Screens/HomeView.xaml | 1 - .../Views/Screens/ModuleRootView.xaml | 25 +++++++++++ src/Artemis.UI/Views/Screens/RootView.xaml | 3 +- src/Artemis.UI/Views/Screens/SplashView.xaml | 42 +++++++++---------- src/Artemis.UI/packages.config | 1 + 26 files changed, 181 insertions(+), 76 deletions(-) create mode 100644 src/Artemis.UI/Ninject/Factories/ModuleViewModelFactory.cs create mode 100644 src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs delete mode 100644 src/Artemis.UI/ViewModels/Interfaces/IEditorViewModel.cs delete mode 100644 src/Artemis.UI/ViewModels/Interfaces/IHomeViewModel.cs delete mode 100644 src/Artemis.UI/ViewModels/Interfaces/ISettingsViewModel.cs create mode 100644 src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs create mode 100644 src/Artemis.UI/Views/Controls/ProfileEditor/ProfileEditorView.xaml create mode 100644 src/Artemis.UI/Views/Screens/ModuleRootView.xaml diff --git a/src/Artemis.Core/Plugins/Abstract/Module.cs b/src/Artemis.Core/Plugins/Abstract/Module.cs index 5526dcea4..e710c3bb6 100644 --- a/src/Artemis.Core/Plugins/Abstract/Module.cs +++ b/src/Artemis.Core/Plugins/Abstract/Module.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System.Collections.Generic; +using System.Drawing; using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Models; using RGB.NET.Core; @@ -42,9 +43,9 @@ namespace Artemis.Core.Plugins.Abstract public abstract void Render(double deltaTime, Surface surface, Graphics graphics); /// - /// Called when the module's main view is being shown + /// Called when the module's view model is being show, return view models here to create tabs for them /// /// - public abstract IScreen GetMainViewModel(); + public abstract IEnumerable GetViewModels(); } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Abstract/ModuleViewModel.cs b/src/Artemis.Core/Plugins/Abstract/ModuleViewModel.cs index 559f5ed42..ead43c4e7 100644 --- a/src/Artemis.Core/Plugins/Abstract/ModuleViewModel.cs +++ b/src/Artemis.Core/Plugins/Abstract/ModuleViewModel.cs @@ -4,11 +4,13 @@ namespace Artemis.Core.Plugins.Abstract { public abstract class ModuleViewModel : Screen { - protected ModuleViewModel(Module module) + protected ModuleViewModel(Module module, string name) { Module = module; + Name = name; } + public string Name { get; } public Module Module { get; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/PluginService.cs b/src/Artemis.Core/Services/PluginService.cs index 8ec5da868..ec4a6e3ee 100644 --- a/src/Artemis.Core/Services/PluginService.cs +++ b/src/Artemis.Core/Services/PluginService.cs @@ -15,6 +15,7 @@ using Ninject; using Ninject.Extensions.ChildKernel; using Ninject.Parameters; using RGB.NET.Core; +using Serilog; namespace Artemis.Core.Services { @@ -24,12 +25,14 @@ namespace Artemis.Core.Services public class PluginService : IPluginService { private readonly IKernel _kernel; + private readonly ILogger _logger; private readonly List _plugins; private IKernel _childKernel; - internal PluginService(IKernel kernel) + internal PluginService(IKernel kernel, ILogger logger) { _kernel = kernel; + _logger = logger; _plugins = new List(); // Ensure the plugins directory exists @@ -114,7 +117,9 @@ namespace Artemis.Core.Services // Load the metadata var metadataFile = Path.Combine(subDirectory.FullName, "plugin.json"); if (!File.Exists(metadataFile)) - throw new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile); + { + _logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception"); + } // Locate the main entry var pluginInfo = JsonConvert.DeserializeObject(File.ReadAllText(metadataFile)); @@ -124,14 +129,21 @@ namespace Artemis.Core.Services } catch (Exception e) { - throw new ArtemisPluginException("Failed to load plugin", e); + _logger.Warning(new ArtemisPluginException("Failed to load plugin", e), "Plugin exception"); } } // Activate plugins after they are all loaded foreach (var pluginInfo in _plugins.Where(p => p.Enabled)) { - pluginInfo.Instance.EnablePlugin(); + try + { + pluginInfo.Instance.EnablePlugin(); + } + catch (Exception e) + { + _logger.Warning(new ArtemisPluginException(pluginInfo, "Failed to load enable plugin", e), "Plugin exception"); + } OnPluginEnabled(new PluginEventArgs(pluginInfo)); } diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs index 3ae230ed6..e1feab291 100644 --- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; @@ -6,15 +7,14 @@ using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; using Artemis.Plugins.Modules.General.ViewModels; -using Stylet; using Device = Artemis.Core.Models.Surface.Device; namespace Artemis.Plugins.Modules.General { public class GeneralModule : Module { - private readonly PluginSettings _settings; private readonly ColorBlend _rainbowColorBlend; + private readonly PluginSettings _settings; public GeneralModule(PluginInfo pluginInfo, PluginSettings settings) : base(pluginInfo) { @@ -118,9 +118,9 @@ namespace Artemis.Plugins.Modules.General } } - public override IScreen GetMainViewModel() + public override IEnumerable GetViewModels() { - return new GeneralViewModel(this); + return new List {new GeneralViewModel(this)}; } public override void Dispose() diff --git a/src/Artemis.Plugins.Modules.General/ViewModels/GeneralViewModel.cs b/src/Artemis.Plugins.Modules.General/ViewModels/GeneralViewModel.cs index b9f75f0f8..7ab14f005 100644 --- a/src/Artemis.Plugins.Modules.General/ViewModels/GeneralViewModel.cs +++ b/src/Artemis.Plugins.Modules.General/ViewModels/GeneralViewModel.cs @@ -5,7 +5,7 @@ namespace Artemis.Plugins.Modules.General.ViewModels { public class GeneralViewModel : ModuleViewModel { - public GeneralViewModel(Module module) : base(module) + public GeneralViewModel(Module module) : base(module, "General") { } } diff --git a/src/Artemis.UI/App.xaml b/src/Artemis.UI/App.xaml index a64915a29..19257ccf3 100644 --- a/src/Artemis.UI/App.xaml +++ b/src/Artemis.UI/App.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="https://github.com/canton7/Stylet" - xmlns:local="clr-namespace:Artemis.UI"> + xmlns:local="clr-namespace:Artemis.UI" + xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"> @@ -28,6 +29,9 @@ Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Teal.xaml" /> + + + @@ -54,6 +58,9 @@ + +