Plugins - Added descriptions

Settings - Plugin settings tab
UI - Catch exceptions during exception dialog display
Plugins - Implemented enable/disable of plugins (WIP)
Novation - Added Launchpad Mini layout and image
This commit is contained in:
Robert committed 2020-03-03 23:18:00 +01:00
1 parent 57d82fafa8
commit c62997ca41
44 files changed
+810 -199

No files matched your search

@@ -0,0 +1,92 @@
// I don't want all of MoreLINQ (https://github.com/morelinq/MoreLINQ) so we'll borrow just this
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using System.Collections.Generic;
namespace Artemis.Core.Extensions
{
public static class IEnumerableExtensions
{
/// <summary>
/// Returns all distinct elements of the given source, where "distinctness"
/// is determined via a projection and the default equality comparer for the projected type.
/// </summary>
/// <remarks>
/// This operator uses deferred execution and streams the results, although
/// a set of already-seen keys is retained. If a key is seen multiple times,
/// only the first element with that key is returned.
/// </remarks>
/// <typeparam name="TSource">Type of the source sequence</typeparam>
/// <typeparam name="TKey">Type of the projected element</typeparam>
/// <param name="source">Source sequence</param>
/// <param name="keySelector">Projection for determining "distinctness"</param>
/// <returns>
/// A sequence consisting of distinct elements from the source sequence,
/// comparing them by the specified key projection.
/// </returns>
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)
{
return source.DistinctBy(keySelector, null);
}
/// <summary>
/// Returns all distinct elements of the given source, where "distinctness"
/// is determined via a projection and the specified comparer for the projected type.
/// </summary>
/// <remarks>
/// This operator uses deferred execution and streams the results, although
/// a set of already-seen keys is retained. If a key is seen multiple times,
/// only the first element with that key is returned.
/// </remarks>
/// <typeparam name="TSource">Type of the source sequence</typeparam>
/// <typeparam name="TKey">Type of the projected element</typeparam>
/// <param name="source">Source sequence</param>
/// <param name="keySelector">Projection for determining "distinctness"</param>
/// <param name="comparer">
/// The equality comparer to use to determine whether or not keys are equal.
/// If null, the default equality comparer for <c>TSource</c> is used.
/// </param>
/// <returns>
/// A sequence consisting of distinct elements from the source sequence,
/// comparing them by the specified key projection.
/// </returns>
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
return _();
IEnumerable<TSource> _()
{
var knownKeys = new HashSet<TKey>(comparer);
foreach (var element in source)
{
if (knownKeys.Add(keySelector(element)))
yield return element;
}
}
}
}
}
@@ -3,7 +3,9 @@ using System.Diagnostics;
using System.IO;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Models;
using Ninject;
using RGB.NET.Core;
using Serilog;
namespace Artemis.Core.Plugins.Abstract
{
@@ -20,6 +22,8 @@ namespace Artemis.Core.Plugins.Abstract
public IRGBDeviceProvider RgbDeviceProvider { get; }
[Inject]
public ILogger Logger { get; set; }
protected void ResolveAbsolutePath(Type type, object sender, ResolvePathEventArgs e)
{
@@ -30,7 +34,24 @@ namespace Artemis.Core.Plugins.Abstract
e.FinalPath = Path.Combine(PluginInfo.Directory.FullName, e.RelativePart, e.FileName);
else if (e.RelativePath != null)
e.FinalPath = Path.Combine(PluginInfo.Directory.FullName, e.RelativePath);
var deviceInfo = ((IRGBDevice) sender).DeviceInfo;
if (e.FileName != null && !File.Exists(e.FinalPath))
{
Logger?.Information("Couldn't find a layout for device {deviceName}, model {deviceModel} at {filePath}",
deviceInfo.DeviceName, deviceInfo.Model, e.FinalPath);
}
}
}
public override void Dispose()
{
// Does not happen with device providers, they require Artemis to restart
}
public override void DisablePlugin()
{
// Does not happen with device providers, they require Artemis to restart
}
}
}
@@ -31,6 +31,12 @@ namespace Artemis.Core.Plugins.Models
/// </summary>
public string Description { get; set; }
/// <summary>
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for available
/// icons
/// </summary>
public string Icon { get; set; }
/// <summary>
/// The version of the plugin
/// </summary>
@@ -78,7 +84,7 @@ namespace Artemis.Core.Plugins.Models
/// </summary>
[JsonIgnore]
internal PluginEntity PluginEntity { get; set; }
public override string ToString()
{
return $"{nameof(Guid)}: {Guid}, {nameof(Name)}: {Name}, {nameof(Version)}: {Version}";
+13 -6
View File
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Extensions;
@@ -10,6 +12,7 @@ using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Utilities;
using Artemis.Storage.Entities.Plugins;
using Artemis.Storage.Repositories.Interfaces;
using McMaster.NETCore.Plugins;
@@ -219,7 +222,7 @@ namespace Artemis.Core.Services
var pluginEntity = _pluginRepository.GetPluginByGuid(pluginInfo.Guid);
if (pluginEntity == null)
pluginEntity = new PluginEntity {PluginGuid = pluginInfo.Guid, IsEnabled = true, LastEnableSuccessful = true};
pluginInfo.PluginEntity = pluginEntity;
pluginInfo.Enabled = pluginEntity.IsEnabled;
@@ -332,7 +335,7 @@ namespace Artemis.Core.Services
plugin.PluginInfo.PluginEntity.LastEnableSuccessful = true;
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
}
OnPluginEnabled(new PluginEventArgs(plugin.PluginInfo));
}
@@ -342,11 +345,15 @@ namespace Artemis.Core.Services
plugin.PluginInfo.PluginEntity.IsEnabled = false;
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
// Device providers cannot be disabled at runtime, restart the application
if (plugin is DeviceProvider)
{
CurrentProcessUtilities.RestartSelf();
return;
}
plugin.DisablePlugin();
// We got this far so the plugin enabled and we didn't crash horribly, yay
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
OnPluginDisabled(new PluginEventArgs(plugin.PluginInfo));
}
@@ -0,0 +1,27 @@
using System.Diagnostics;
using System.Windows;
using Stylet;
namespace Artemis.Core.Utilities
{
public static class CurrentProcessUtilities
{
public static string GetCurrentLocation()
{
return Process.GetCurrentProcess().MainModule.FileName;
}
public static void RestartSelf()
{
var info = new ProcessStartInfo
{
Arguments = "/C choice /C Y /N /D Y /T 5 & START /wait taskkill /f /im \"Artemis.UI.exe\" & START \"\" \"" + GetCurrentLocation() + "\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
};
Process.Start(info);
Execute.OnUIThread(() => Application.Current.Shutdown());
}
}
}