mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
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:
1 parent
38c04913e2
commit
fe933f60e8
17 files changed
+195
-135
No files matched your search
+19
-4
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user