Update service - Removed option to install updates without asking

Modules - Decrease CPU usage for activation requirements check by using a centralized service
Devices - Reload provider when unloading a layout
This commit is contained in:
Robert committed 2021-06-10 17:41:54 +02:00
1 parent 38c04913e2
commit fe933f60e8
17 files changed
+195 -135

No files matched your search

@@ -549,11 +549,6 @@ namespace Artemis.Core
else
LogicalLayout = DeviceEntity.LogicalLayout;
}
public void ClearLayout()
{
// TODO
}
}
/// <summary>
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Artemis.Core.Services;
using Ninject;
namespace Artemis.Core.Modules
{
@@ -11,6 +13,8 @@ namespace Artemis.Core.Modules
/// </summary>
public class ProcessActivationRequirement : IModuleActivationRequirement
{
private readonly IProcessMonitorService _processMonitorService;
/// <summary>
/// Creates a new instance of the <see cref="ProcessActivationRequirement" /> class
/// </summary>
@@ -18,6 +22,14 @@ namespace Artemis.Core.Modules
/// <param name="location">The location of where the process must be running from (optional)</param>
public ProcessActivationRequirement(string? processName, string? location = null)
{
if (string.IsNullOrWhiteSpace(ProcessName) && string.IsNullOrWhiteSpace(Location))
throw new ArgumentNullException($"Atleast one {nameof(processName)} and {nameof(location)} must not be null");
// Let's not make a habit out of this :P
if (CoreService.Kernel == null)
throw new ArtemisCoreException("Cannot create a ProcessActivationRequirement before initializing the Core");
_processMonitorService = CoreService.Kernel.Get<IProcessMonitorService>();
ProcessName = processName;
Location = location;
}
@@ -38,10 +50,13 @@ namespace Artemis.Core.Modules
if (ProcessName == null && Location == null)
return false;
IEnumerable<Process> processes = ProcessName != null ? Process.GetProcessesByName(ProcessName).Where(p => !p.HasExited) : Process.GetProcesses().Where(p => !p.HasExited);
return Location != null
? processes.Any(p => string.Equals(Path.GetDirectoryName(p.GetProcessFilename()), Location, StringComparison.CurrentCultureIgnoreCase))
: processes.Any();
IEnumerable<Process> processes = _processMonitorService.GetRunningProcesses().Where(p => !p.HasExited);
if (ProcessName != null)
processes = processes.Where(p => string.Equals(p.ProcessName, ProcessName, StringComparison.InvariantCultureIgnoreCase));
if (Location != null)
processes = processes.Where(p => string.Equals(Path.GetDirectoryName(p.GetProcessFilename()), Location, StringComparison.InvariantCultureIgnoreCase));
return processes.Any();
}
/// <inheritdoc />
@@ -22,6 +22,8 @@ namespace Artemis.Core
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action, string? name)
{
if (CoreService.Kernel == null)
throw new ArtemisCoreException("Cannot create a TimedUpdateRegistration before initializing the Core");
_logger = CoreService.Kernel.Get<ILogger>();
Feature = feature;
@@ -37,6 +39,8 @@ namespace Artemis.Core
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Func<double, Task> asyncAction, string? name)
{
if (CoreService.Kernel == null)
throw new ArtemisCoreException("Cannot create a TimedUpdateRegistration before initializing the Core");
_logger = CoreService.Kernel.Get<ILogger>();
Feature = feature;
+2 -2
View File
@@ -22,7 +22,7 @@ namespace Artemis.Core.Services
/// </summary>
internal class CoreService : ICoreService
{
internal static IKernel Kernel = null!;
internal static IKernel? Kernel;
private readonly Stopwatch _frameStopWatch;
private readonly ILogger _logger;
@@ -201,7 +201,7 @@ namespace Artemis.Core.Services
Version? hidSharpVersion = Assembly.GetAssembly(typeof(HidDevice))!.GetName().Version;
_logger.Debug("Forcing plugins to use HidSharp {hidSharpVersion}", hidSharpVersion);
DeserializationLogger.Initialize(Kernel);
DeserializationLogger.Initialize(Kernel!);
// Initialize the services
_pluginManagementService.CopyBuiltInPlugins();
+20 -3
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using Artemis.Core.DeviceProviders;
using Artemis.Core.Services.Models;
using Artemis.Core.SkiaSharp;
@@ -345,6 +346,13 @@ namespace Artemis.Core.Services
return layout;
}
if (device.DisableDefaultLayout)
{
layout = null;
ApplyDeviceLayout(device, layout);
return null;
}
// Look for a layout provided by the plugin
layout = device.DeviceProvider.LoadLayout(device);
if (layout.IsValid)
@@ -354,8 +362,7 @@ namespace Artemis.Core.Services
}
// Finally fall back to a default layout
if (!device.DisableDefaultLayout)
layout = ArtemisLayout.GetDefaultLayout(device);
layout = ArtemisLayout.GetDefaultLayout(device);
ApplyDeviceLayout(device, layout);
return layout;
}
@@ -365,7 +372,7 @@ namespace Artemis.Core.Services
if (layout == null)
{
if (device.Layout != null)
device.ClearLayout();
ReloadDevice(device);
return;
}
@@ -377,6 +384,16 @@ namespace Artemis.Core.Services
UpdateLedGroup();
}
private void ReloadDevice(ArtemisDevice device)
{
DeviceProvider deviceProvider = device.DeviceProvider;
// Feels bad but need to in order to get the initial LEDs back
_pluginManagementService.DisablePluginFeature(deviceProvider, false);
Thread.Sleep(500);
_pluginManagementService.EnablePluginFeature(deviceProvider, false);
}
public ArtemisDevice? GetDevice(IRGBDevice rgbDevice)
{
return _devices.FirstOrDefault(d => d.RgbDevice == rgbDevice);