1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Plugins working again

This commit is contained in:
SpoinkyNL 2018-03-02 23:46:55 +01:00
parent 25f832cba5
commit 7a2717d8b9
17 changed files with 108 additions and 122 deletions

View File

@ -208,10 +208,6 @@
<Project>{cd23bc5e-57f0-46ce-a007-24d031146219}</Project> <Project>{cd23bc5e-57f0-46ce-a007-24d031146219}</Project>
<Name>Artemis.Plugins</Name> <Name>Artemis.Plugins</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Module.General\Module.General.csproj">
<Project>{58113cc5-a9ca-4ec3-ab4e-3c94b99268d8}</Project>
<Name>Module.General</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Models\" /> <Folder Include="Models\" />

View File

@ -1,5 +1,9 @@
using Artemis.Core.Services.Interfaces; using System.Linq;
using System.Reflection;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Interfaces; using Artemis.Plugins.Interfaces;
using Artemis.Plugins.Models;
using Newtonsoft.Json;
using Ninject.Extensions.Conventions; using Ninject.Extensions.Conventions;
using Ninject.Modules; using Ninject.Modules;
@ -18,15 +22,6 @@ namespace Artemis.Core.Ninject
.BindAllInterfaces() .BindAllInterfaces()
.Configure(c => c.InSingletonScope()); .Configure(c => c.InSingletonScope());
}); });
// Bind all built-in plugins
Kernel.Bind(x =>
{
x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<IPlugin>()
.BindAllBaseClasses();
});
} }
} }
} }

View File

@ -42,10 +42,6 @@ namespace Artemis.Core.Services
pluginInfo.Dispose(); pluginInfo.Dispose();
_plugins.Clear(); _plugins.Clear();
// Load all built-in plugins
foreach (var builtInPlugin in _kernel.GetAll<IPlugin>())
_plugins.Add(PluginInfo.FromBuiltInPlugin(_kernel, builtInPlugin));
// Iterate all plugin folders and load each plugin // Iterate all plugin folders and load each plugin
foreach (var directory in Directory.GetDirectories(Constants.DataFolder + "plugins")) foreach (var directory in Directory.GetDirectories(Constants.DataFolder + "plugins"))
_plugins.Add(await PluginInfo.FromFolder(_kernel, directory)); _plugins.Add(await PluginInfo.FromFolder(_kernel, directory));
@ -53,11 +49,13 @@ namespace Artemis.Core.Services
OnFinishedLoadedPlugins(); OnFinishedLoadedPlugins();
} }
/// <inheritdoc />
public async Task ReloadPlugin(PluginInfo pluginInfo) public async Task ReloadPlugin(PluginInfo pluginInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
public async Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo) public async Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo)
{ {
return await pluginInfo.GetModuleViewModel(_kernel); return await pluginInfo.GetModuleViewModel(_kernel);

View File

@ -43,7 +43,8 @@ namespace Artemis.Core.Services
await Task.Run(() => await Task.Run(() =>
{ {
// TODO SpoinkyNL 8-1-18: Keep settings into account // TODO SpoinkyNL 8-1-18: Keep settings into account
Surface.LoadDevices(AsusDeviceProvider.Instance); // This one doesn't work well without ASUS devices installed
// Surface.LoadDevices(AsusDeviceProvider.Instance);
Surface.LoadDevices(CoolerMasterDeviceProvider.Instance); Surface.LoadDevices(CoolerMasterDeviceProvider.Instance);
Surface.LoadDevices(CorsairDeviceProvider.Instance); Surface.LoadDevices(CorsairDeviceProvider.Instance);
Surface.LoadDevices(DMXDeviceProvider.Instance); Surface.LoadDevices(DMXDeviceProvider.Instance);

View File

@ -47,13 +47,27 @@ namespace Artemis.Plugins.Models
public string Folder { get; set; } public string Folder { get; set; }
/// <summary> /// <summary>
/// Indicates wether this is a built-in plugin. Built-in plugins are precompiled and have no files /// Indicates wether this is a built-in plugin.
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public bool IsBuiltIn { get; private set; } public bool IsBuiltIn { get; private set; }
public void Dispose()
{
Plugin.UnloadPlugin();
}
/// <summary>
/// Load a plugin from a folder
/// </summary>
/// <param name="kernel">The Ninject kernel to use for DI</param>
/// <param name="folder">The folder in which plugin.json is located</param>
/// <returns></returns>
public static async Task<PluginInfo> FromFolder(IKernel kernel, string folder) public static async Task<PluginInfo> FromFolder(IKernel kernel, string folder)
{ {
// Make sure the right engine is used
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
if (!folder.EndsWith("\\")) if (!folder.EndsWith("\\"))
folder += "\\"; folder += "\\";
if (!File.Exists(folder + "plugin.json")) if (!File.Exists(folder + "plugin.json"))
@ -77,32 +91,23 @@ namespace Artemis.Plugins.Models
return pluginInfo; return pluginInfo;
} }
public static PluginInfo FromBuiltInPlugin(IKernel kernel, IPlugin builtInPlugin) /// <summary>
{ /// Gets the view model of the module accompanying the provided plugin info
var pluginInfo = new PluginInfo /// </summary>
{ /// <param name="kernel">The Ninject kernel to use for DI</param>
Name = builtInPlugin.GetType().Name, /// <returns></returns>
Version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion,
Plugin = builtInPlugin,
IsBuiltIn = true
};
pluginInfo.Plugin.LoadPlugin();
return pluginInfo;
}
public void Dispose()
{
}
public async Task<IModuleViewModel> GetModuleViewModel(IKernel kernel) public async Task<IModuleViewModel> GetModuleViewModel(IKernel kernel)
{ {
// Make sure the right engine is used
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
// Don't attempt to locave VMs for something other than a module // Don't attempt to locave VMs for something other than a module
if (Plugin is IModule) if (!(Plugin is IModule))
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module."); throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module.");
// Compile the ViewModel script and get the type // Use the plugin's assembly as the VM is precompiled if built in, otherwise compile the VM into a new assembly
var assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(Folder + ViewModel)); var assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(Folder + ViewModel));
var vmType = assembly.GetTypes().Where(t => typeof(IModuleViewModel).IsAssignableFrom(t)).ToList(); var vmType = assembly.GetTypes().Where(t => typeof(IModuleViewModel).IsAssignableFrom(t)).ToList();
if (!vmType.Any()) if (!vmType.Any())
throw new ArtemisPluginException(this, "Failed to load plugin, no type found that implements IModuleViewModel"); throw new ArtemisPluginException(this, "Failed to load plugin, no type found that implements IModuleViewModel");

View File

@ -1,28 +1,30 @@
using System; using System;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Interfaces; using Artemis.Plugins.Interfaces;
namespace Artemis.BuiltIn.Module.General namespace Module.General
{ {
public class GeneralModule : IModule public class GeneralModule : IModule
{ {
public GeneralModule(ICoreService coreService)
{
Console.WriteLine(coreService);
}
public void LoadPlugin() public void LoadPlugin()
{ {
throw new NotImplementedException();
} }
public void UnloadPlugin() public void UnloadPlugin()
{ {
throw new NotImplementedException();
} }
public void Update(double deltaTime) public void Update(double deltaTime)
{ {
throw new NotImplementedException();
} }
public void Render(double deltaTime) public void Render(double deltaTime)
{ {
throw new NotImplementedException();
} }
} }
} }

View File

@ -1,12 +1,8 @@
<UserControl x:Class="Artemis.BuiltIn.Module.General.GeneralView" <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.BuiltIn.Module.General"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"> d:DesignHeight="300" d:DesignWidth="300">
<Grid> <Grid />
</Grid>
</UserControl> </UserControl>

View File

@ -1,15 +0,0 @@
using System.Windows.Controls;
namespace Artemis.BuiltIn.Module.General
{
/// <summary>
/// Interaction logic for GeneralView.xaml
/// </summary>
public partial class GeneralView : UserControl
{
public GeneralView()
{
InitializeComponent();
}
}
}

View File

@ -1,6 +1,11 @@
namespace Artemis.BuiltIn.Module.General using Artemis.Plugins.Interfaces;
using Artemis.Plugins.Models;
using Stylet;
namespace Module.General
{ {
public class GeneralViewModel public class GeneralViewModel : Screen, IModuleViewModel
{ {
public PluginInfo PluginInfo { get; set; }
} }
} }

View File

@ -7,7 +7,7 @@
<ProjectGuid>{58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}</ProjectGuid> <ProjectGuid>{58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Artemis.BuiltIn.Module.General</RootNamespace> <RootNamespace>Module.General</RootNamespace>
<AssemblyName>Module.General</AssemblyName> <AssemblyName>Module.General</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
@ -33,6 +33,9 @@
<ItemGroup> <ItemGroup>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="Stylet, Version=1.1.21.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.1.21\lib\net45\Stylet.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@ -48,13 +51,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="GeneralModule.cs" /> <Compile Include="GeneralModule.cs" />
<Compile Include="GeneralView.xaml.cs">
<DependentUpon>GeneralView.xaml</DependentUpon>
</Compile>
<Compile Include="GeneralViewModel.cs" /> <Compile Include="GeneralViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Artemis.Core\Artemis.Core.csproj">
<Project>{9B811F9B-86B9-4771-87AF-72BAE7078A36}</Project>
<Name>Artemis.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Artemis.Plugins\Artemis.Plugins.csproj"> <ProjectReference Include="..\Artemis.Plugins\Artemis.Plugins.csproj">
<Project>{CD23BC5E-57F0-46CE-A007-24D031146219}</Project> <Project>{CD23BC5E-57F0-46CE-A007-24D031146219}</Project>
<Name>Artemis.Plugins</Name> <Name>Artemis.Plugins</Name>
@ -68,6 +72,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" />
<None Include="plugin.json" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@ -34,6 +35,17 @@
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.4.0" newVersion="3.3.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Stylet" version="1.1.21" targetFramework="net46" />
</packages>

View File

@ -0,0 +1,6 @@
{
"Name": "Default",
"Version": "1.0.0",
"Main": "GeneralModule.cs",
"ViewModel": "GeneralViewModel.cs"
}

View File

@ -1,10 +0,0 @@
<UserControl x:Class="TestModule.TestModuleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestModule"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid />
</UserControl>

View File

@ -1,6 +0,0 @@
namespace TestModule
{
public class TestModuleViewModel
{
}
}

View File

@ -1,8 +0,0 @@
using Artemis.Core.Plugins.Interfaces;
namespace TestModule
{
public class TestModule : IModule
{
}
}