Auto-run - Moved to task-based approach (WIP)

This commit is contained in:
SpoinkyNL committed 2021-01-24 23:16:13 +01:00
1 parent b4458ddefd
commit 097a5275e2
12 files changed
+424 -43

No files matched your search

@@ -198,9 +198,9 @@ namespace Artemis.Core.Services
// ReSharper disable InconsistentlySynchronizedField - It's read-only, idc
_logger.Debug("Loaded {count} plugin(s)", _plugins.Count);
bool mustElevate = !isElevated && _plugins.Any(p => p.Entity.IsEnabled && p.Info.RequiresAdmin);
if (mustElevate)
bool adminRequired = _plugins.Any(p => p.Entity.IsEnabled && p.Info.RequiresAdmin);
if (!isElevated && adminRequired)
{
_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
@@ -208,6 +208,13 @@ namespace Artemis.Core.Services
return;
}
if (isElevated && !adminRequired)
{
// No need for a delay this early on, nothing that needs graceful shutdown is happening yet
Utilities.Restart(false, TimeSpan.Zero);
return;
}
foreach (Plugin plugin in _plugins.Where(p => p.Entity.IsEnabled))
EnablePlugin(plugin, false, ignorePluginLock);
+8 -9
View File
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
@@ -35,7 +34,7 @@ namespace Artemis.Core
}
/// <summary>
/// Restarts the application
/// Restarts the application
/// </summary>
/// <param name="elevate">Whether the application should be restarted with elevated permissions</param>
/// <param name="delay">Delay in seconds before killing process and restarting </param>
@@ -90,6 +89,11 @@ namespace Artemis.Core
}
}
private static void OnRestartRequested(RestartEventArgs e)
{
RestartRequested?.Invoke(null, e);
}
#region Events
/// <summary>
@@ -98,20 +102,15 @@ namespace Artemis.Core
public static event EventHandler? ShutdownRequested;
/// <summary>
/// Occurs when the core has requested an application restart
/// Occurs when the core has requested an application restart
/// </summary>
public static event EventHandler<RestartEventArgs>? RestartRequested;
private static void OnShutdownRequested()
{
ShutdownRequested?.Invoke(null, EventArgs.Empty);
}
#endregion
private static void OnRestartRequested(RestartEventArgs e)
{
RestartRequested?.Invoke(null, e);
}
}
}