mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Added RequiresAdmin boolean
Utilities - Simplified shutdown method signature Utilities - Added restart method with option to elevate Core - Moved actual shutdown/restart logic to UI
This commit is contained in:
1 parent
281c18200a
commit
de5b8e4458
12 files changed
+151
-39
No files matched your search
@@ -78,6 +78,7 @@ namespace Artemis.Core.Services
|
||||
public TimeSpan FrameTime { get; private set; }
|
||||
public bool ModuleRenderingDisabled { get; set; }
|
||||
public List<string>? StartupArguments { get; set; }
|
||||
public bool IsElevated { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -93,18 +94,27 @@ namespace Artemis.Core.Services
|
||||
throw new ArtemisCoreException("Cannot initialize the core as it is already initialized.");
|
||||
|
||||
AssemblyInformationalVersionAttribute? versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
_logger.Information("Initializing Artemis Core version {version}, build {buildNumber} branch {branch}.", versionAttribute?.InformationalVersion, Constants.BuildInfo.BuildNumber,
|
||||
Constants.BuildInfo.SourceBranch);
|
||||
// This should prevent a certain someone from removing HidSharp as an unused dependency as well
|
||||
_logger.Information("Forcing plugins to use HidSharp {hidSharpVersion}", Assembly.GetAssembly(typeof(HidDevice))!.GetName().Version);
|
||||
_logger.Information(
|
||||
"Initializing Artemis Core version {version}, build {buildNumber} branch {branch}.",
|
||||
versionAttribute?.InformationalVersion,
|
||||
Constants.BuildInfo.BuildNumber,
|
||||
Constants.BuildInfo.SourceBranch
|
||||
);
|
||||
_logger.Information("Startup arguments: {args}", StartupArguments);
|
||||
_logger.Information("Elevated permissions: {perms}", IsElevated);
|
||||
|
||||
ApplyLoggingLevel();
|
||||
|
||||
// Don't remove even if it looks useless
|
||||
// Just this line should prevent a certain someone from removing HidSharp as an unused dependency as well
|
||||
Version? hidSharpVersion = Assembly.GetAssembly(typeof(HidDevice))!.GetName().Version;
|
||||
_logger.Debug("Forcing plugins to use HidSharp {hidSharpVersion}", hidSharpVersion);
|
||||
|
||||
DeserializationLogger.Initialize(Kernel);
|
||||
|
||||
// Initialize the services
|
||||
_pluginManagementService.CopyBuiltInPlugins();
|
||||
_pluginManagementService.LoadPlugins(StartupArguments != null && StartupArguments.Contains("--ignore-plugin-lock"));
|
||||
_pluginManagementService.LoadPlugins(StartupArguments != null && StartupArguments.Contains("--ignore-plugin-lock"), IsElevated);
|
||||
|
||||
ArtemisSurface surfaceConfig = _surfaceService.ActiveSurface;
|
||||
_logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.EntityId);
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
List<string>? StartupArguments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether Artemis is running in an elevated environment (admin permissions)
|
||||
/// </summary>
|
||||
bool IsElevated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the core, only call once
|
||||
/// </summary>
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Artemis.Core.Services
|
||||
/// <summary>
|
||||
/// Loads all installed plugins. If plugins already loaded this will reload them all
|
||||
/// </summary>
|
||||
void LoadPlugins(bool ignorePluginLock);
|
||||
void LoadPlugins(bool ignorePluginLock, bool isElevated);
|
||||
|
||||
/// <summary>
|
||||
/// Unloads all installed plugins.
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
#region Plugins
|
||||
|
||||
public void LoadPlugins(bool ignorePluginLock)
|
||||
public void LoadPlugins(bool ignorePluginLock, bool isElevated)
|
||||
{
|
||||
if (LoadingPlugins)
|
||||
throw new ArtemisCoreException("Cannot load plugins while a previous load hasn't been completed yet.");
|
||||
@@ -188,9 +188,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
Plugin plugin = LoadPlugin(subDirectory);
|
||||
if (plugin.Entity.IsEnabled)
|
||||
EnablePlugin(plugin, false, ignorePluginLock);
|
||||
LoadPlugin(subDirectory);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -198,6 +196,25 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
lock (_plugins)
|
||||
{
|
||||
_logger.Debug("Loaded {count} plugin(s)", _plugins.Count);
|
||||
|
||||
bool mustElevate = !isElevated && _plugins.Any(p => p.Entity.IsEnabled && p.Info.RequiresAdmin);
|
||||
if (mustElevate)
|
||||
{
|
||||
_logger.Information("Restarting because one or more plugins requires elevation");
|
||||
// No need for a delay this early on, nothing that needs graceful shutdown is happening yet
|
||||
Utilities.Restart(true, TimeSpan.Zero);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Plugin plugin in _plugins.Where(p => p.Entity.IsEnabled))
|
||||
EnablePlugin(plugin, false, ignorePluginLock);
|
||||
|
||||
_logger.Debug("Enabled {count} plugin(s)", _plugins.Where(p => p.IsEnabled).Sum(p => p.Features.Count(f => f.IsEnabled)));
|
||||
}
|
||||
|
||||
LoadingPlugins = false;
|
||||
}
|
||||
|
||||
@@ -217,7 +234,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
public Plugin LoadPlugin(DirectoryInfo directory)
|
||||
{
|
||||
_logger.Debug("Loading plugin from {directory}", directory.FullName);
|
||||
_logger.Verbose("Loading plugin from {directory}", directory.FullName);
|
||||
|
||||
// Load the metadata
|
||||
string metadataFile = Path.Combine(directory.FullName, "plugin.json");
|
||||
@@ -411,8 +428,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void EnablePluginFeature(PluginFeature pluginFeature, bool saveState, bool isAutoEnable)
|
||||
{
|
||||
_logger.Debug("Enabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
|
||||
_logger.Verbose("Enabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
|
||||
OnPluginFeatureEnabling(new PluginFeatureEventArgs(pluginFeature));
|
||||
try
|
||||
@@ -443,7 +459,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
if (pluginFeature.IsEnabled)
|
||||
{
|
||||
_logger.Debug("Successfully enabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
_logger.Verbose("Successfully enabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
OnPluginFeatureEnabled(new PluginFeatureEventArgs(pluginFeature));
|
||||
}
|
||||
else
|
||||
@@ -457,7 +473,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.Debug("Disabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
_logger.Verbose("Disabling plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
pluginFeature.SetEnabled(false);
|
||||
}
|
||||
finally
|
||||
@@ -470,7 +486,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
if (!pluginFeature.IsEnabled)
|
||||
{
|
||||
_logger.Debug("Successfully disabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
_logger.Verbose("Successfully disabled plugin feature {feature} - {plugin}", pluginFeature, pluginFeature.Plugin);
|
||||
OnPluginFeatureDisabled(new PluginFeatureEventArgs(pluginFeature));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user