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:
parent
25f832cba5
commit
7a2717d8b9
@ -208,10 +208,6 @@
|
||||
<Project>{cd23bc5e-57f0-46ce-a007-24d031146219}</Project>
|
||||
<Name>Artemis.Plugins</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Module.General\Module.General.csproj">
|
||||
<Project>{58113cc5-a9ca-4ec3-ab4e-3c94b99268d8}</Project>
|
||||
<Name>Module.General</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
|
||||
@ -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.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Modules;
|
||||
|
||||
@ -18,15 +22,6 @@ namespace Artemis.Core.Ninject
|
||||
.BindAllInterfaces()
|
||||
.Configure(c => c.InSingletonScope());
|
||||
});
|
||||
|
||||
// Bind all built-in plugins
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
x.FromThisAssembly()
|
||||
.SelectAllClasses()
|
||||
.InheritedFrom<IPlugin>()
|
||||
.BindAllBaseClasses();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,10 +42,6 @@ namespace Artemis.Core.Services
|
||||
pluginInfo.Dispose();
|
||||
_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
|
||||
foreach (var directory in Directory.GetDirectories(Constants.DataFolder + "plugins"))
|
||||
_plugins.Add(await PluginInfo.FromFolder(_kernel, directory));
|
||||
@ -53,11 +49,13 @@ namespace Artemis.Core.Services
|
||||
OnFinishedLoadedPlugins();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ReloadPlugin(PluginInfo pluginInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo)
|
||||
{
|
||||
return await pluginInfo.GetModuleViewModel(_kernel);
|
||||
|
||||
@ -43,7 +43,8 @@ namespace Artemis.Core.Services
|
||||
await Task.Run(() =>
|
||||
{
|
||||
// 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(CorsairDeviceProvider.Instance);
|
||||
Surface.LoadDevices(DMXDeviceProvider.Instance);
|
||||
|
||||
@ -47,13 +47,27 @@ namespace Artemis.Plugins.Models
|
||||
public string Folder { get; set; }
|
||||
|
||||
/// <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>
|
||||
[JsonIgnore]
|
||||
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)
|
||||
{
|
||||
// Make sure the right engine is used
|
||||
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
|
||||
if (!folder.EndsWith("\\"))
|
||||
folder += "\\";
|
||||
if (!File.Exists(folder + "plugin.json"))
|
||||
@ -76,33 +90,24 @@ namespace Artemis.Plugins.Models
|
||||
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
public static PluginInfo FromBuiltInPlugin(IKernel kernel, IPlugin builtInPlugin)
|
||||
{
|
||||
var pluginInfo = new PluginInfo
|
||||
{
|
||||
Name = builtInPlugin.GetType().Name,
|
||||
Version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion,
|
||||
Plugin = builtInPlugin,
|
||||
IsBuiltIn = true
|
||||
};
|
||||
pluginInfo.Plugin.LoadPlugin();
|
||||
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view model of the module accompanying the provided plugin info
|
||||
/// </summary>
|
||||
/// <param name="kernel">The Ninject kernel to use for DI</param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
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.");
|
||||
|
||||
// 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 vmType = assembly.GetTypes().Where(t => typeof(IModuleViewModel).IsAssignableFrom(t)).ToList();
|
||||
if (!vmType.Any())
|
||||
throw new ArtemisPluginException(this, "Failed to load plugin, no type found that implements IModuleViewModel");
|
||||
@ -110,7 +115,7 @@ namespace Artemis.Plugins.Models
|
||||
throw new ArtemisPluginException(this, "Failed to load plugin, more than one type found that implements IModuleViewModel");
|
||||
|
||||
// Instantiate the ViewModel with Ninject
|
||||
var vm = (IModuleViewModel)kernel.Get(vmType.First());
|
||||
var vm = (IModuleViewModel) kernel.Get(vmType.First());
|
||||
vm.PluginInfo = this;
|
||||
return vm;
|
||||
}
|
||||
|
||||
@ -1,28 +1,30 @@
|
||||
using System;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.BuiltIn.Module.General
|
||||
namespace Module.General
|
||||
{
|
||||
public class GeneralModule : IModule
|
||||
{
|
||||
public GeneralModule(ICoreService coreService)
|
||||
{
|
||||
Console.WriteLine(coreService);
|
||||
}
|
||||
|
||||
public void LoadPlugin()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UnloadPlugin()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Render(double deltaTime)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,8 @@
|
||||
<UserControl x:Class="Artemis.BuiltIn.Module.General.GeneralView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
<UserControl 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:Artemis.BuiltIn.Module.General"
|
||||
mc:Ignorable="d"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<Grid />
|
||||
</UserControl>
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
<ProjectGuid>{58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Artemis.BuiltIn.Module.General</RootNamespace>
|
||||
<RootNamespace>Module.General</RootNamespace>
|
||||
<AssemblyName>Module.General</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
@ -33,6 +33,9 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<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.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@ -48,13 +51,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GeneralModule.cs" />
|
||||
<Compile Include="GeneralView.xaml.cs">
|
||||
<DependentUpon>GeneralView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GeneralViewModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</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">
|
||||
<Project>{CD23BC5E-57F0-46CE-A007-24D031146219}</Project>
|
||||
<Name>Artemis.Plugins</Name>
|
||||
@ -68,6 +72,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="plugin.json" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@ -1,39 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0"/>
|
||||
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
|
||||
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</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>
|
||||
</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>
|
||||
4
src/Module.General/packages.config
Normal file
4
src/Module.General/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Stylet" version="1.1.21" targetFramework="net46" />
|
||||
</packages>
|
||||
6
src/Module.General/plugin.json
Normal file
6
src/Module.General/plugin.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"Name": "Default",
|
||||
"Version": "1.0.0",
|
||||
"Main": "GeneralModule.cs",
|
||||
"ViewModel": "GeneralViewModel.cs"
|
||||
}
|
||||
@ -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>
|
||||
@ -1,6 +0,0 @@
|
||||
namespace TestModule
|
||||
{
|
||||
public class TestModuleViewModel
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
|
||||
namespace TestModule
|
||||
{
|
||||
public class TestModule : IModule
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user