mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 01:42:02 +00:00
Plugins - Added timeout for plugin enable
Plugins - Delete lock file even on exception, only leave it in place on crash Plugins - Added --ignore-plugin-lock startup argument UI - Renamed -autorun argument to --autorun
This commit is contained in:
parent
c80e5e42aa
commit
58e07ae5bd
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.Plugins.Abstract.ViewModels;
|
using Artemis.Core.Plugins.Abstract.ViewModels;
|
||||||
using Artemis.Core.Plugins.Exceptions;
|
using Artemis.Core.Plugins.Exceptions;
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
@ -11,7 +12,7 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Plugin : IDisposable
|
public abstract class Plugin : IDisposable
|
||||||
{
|
{
|
||||||
public PluginInfo PluginInfo { get; internal set; }
|
public PluginInfo PluginInfo { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the plugin is enabled
|
/// Gets whether the plugin is enabled
|
||||||
@ -60,7 +61,7 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
// Don't wrap existing lock exceptions, simply rethrow them
|
// Don't wrap existing lock exceptions, simply rethrow them
|
||||||
if (PluginInfo.LoadException is ArtemisPluginLockException)
|
if (PluginInfo.LoadException is ArtemisPluginLockException)
|
||||||
throw PluginInfo.LoadException;
|
throw PluginInfo.LoadException;
|
||||||
|
|
||||||
throw new ArtemisPluginLockException(PluginInfo.LoadException);
|
throw new ArtemisPluginLockException(PluginInfo.LoadException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,9 +69,15 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
PluginInfo.Enabled = true;
|
PluginInfo.Enabled = true;
|
||||||
PluginInfo.CreateLockFile();
|
PluginInfo.CreateLockFile();
|
||||||
|
|
||||||
InternalEnablePlugin();
|
// Allow up to 15 seconds for plugins to activate.
|
||||||
OnPluginEnabled();
|
// This means plugins that need more time should do their long running tasks in a background thread, which is intentional
|
||||||
|
// Little meh: Running this from a different thread could cause deadlocks
|
||||||
|
var enableTask = Task.Run(InternalEnablePlugin);
|
||||||
|
if (!enableTask.Wait(TimeSpan.FromSeconds(15)))
|
||||||
|
throw new ArtemisPluginException(PluginInfo, "Plugin load timeout");
|
||||||
|
|
||||||
PluginInfo.LoadException = null;
|
PluginInfo.LoadException = null;
|
||||||
|
OnPluginEnabled();
|
||||||
}
|
}
|
||||||
// If enable failed, put it back in a disabled state
|
// If enable failed, put it back in a disabled state
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -80,8 +87,11 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
PluginInfo.LoadException = e;
|
PluginInfo.LoadException = e;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
PluginInfo.DeleteLockFile();
|
{
|
||||||
|
if (!(PluginInfo.LoadException is ArtemisPluginLockException))
|
||||||
|
PluginInfo.DeleteLockFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!enable && Enabled)
|
else if (!enable && Enabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -63,6 +63,7 @@ namespace Artemis.Core.Services
|
|||||||
public TimeSpan FrameTime { get; private set; }
|
public TimeSpan FrameTime { get; private set; }
|
||||||
public bool PluginUpdatingDisabled { get; set; }
|
public bool PluginUpdatingDisabled { get; set; }
|
||||||
public bool ModuleRenderingDisabled { get; set; }
|
public bool ModuleRenderingDisabled { get; set; }
|
||||||
|
public List<string> StartupArguments { get; set; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@ -83,7 +84,7 @@ namespace Artemis.Core.Services
|
|||||||
|
|
||||||
// Initialize the services
|
// Initialize the services
|
||||||
_pluginService.CopyBuiltInPlugins();
|
_pluginService.CopyBuiltInPlugins();
|
||||||
_pluginService.LoadPlugins();
|
_pluginService.LoadPlugins(StartupArguments.Contains("--ignore-plugin-lock"));
|
||||||
|
|
||||||
var surfaceConfig = _surfaceService.ActiveSurface;
|
var surfaceConfig = _surfaceService.ActiveSurface;
|
||||||
if (surfaceConfig != null)
|
if (surfaceConfig != null)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Artemis.Core.Events;
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core.Services.Interfaces
|
namespace Artemis.Core.Services.Interfaces
|
||||||
@ -25,6 +26,11 @@ namespace Artemis.Core.Services.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool ModuleRenderingDisabled { get; set; }
|
bool ModuleRenderingDisabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a list of startup arguments
|
||||||
|
/// </summary>
|
||||||
|
List<string> StartupArguments { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the core, only call once
|
/// Initializes the core, only call once
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace Artemis.Core.Services.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads all installed plugins. If plugins already loaded this will reload them all
|
/// Loads all installed plugins. If plugins already loaded this will reload them all
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void LoadPlugins();
|
void LoadPlugins(bool ignorePluginLock);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unloads all installed plugins.
|
/// Unloads all installed plugins.
|
||||||
|
|||||||
@ -107,8 +107,7 @@ namespace Artemis.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
public void LoadPlugins(bool ignorePluginLock)
|
||||||
public void LoadPlugins()
|
|
||||||
{
|
{
|
||||||
if (LoadingPlugins)
|
if (LoadingPlugins)
|
||||||
throw new ArtemisCoreException("Cannot load plugins while a previous load hasn't been completed yet.");
|
throw new ArtemisCoreException("Cannot load plugins while a previous load hasn't been completed yet.");
|
||||||
@ -150,7 +149,7 @@ namespace Artemis.Core.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EnablePlugin(pluginInfo.Instance, true);
|
EnablePlugin(pluginInfo.Instance, !ignorePluginLock);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@ -305,13 +304,13 @@ namespace Artemis.Core.Services
|
|||||||
{
|
{
|
||||||
// On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
|
// On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
|
||||||
// not affect the user's settings
|
// not affect the user's settings
|
||||||
if (isAutoEnable)
|
if (isAutoEnable)
|
||||||
plugin.PluginInfo.Enabled = true;
|
plugin.PluginInfo.Enabled = true;
|
||||||
|
|
||||||
plugin.PluginInfo.ApplyToEntity();
|
plugin.PluginInfo.ApplyToEntity();
|
||||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||||
|
|
||||||
if (plugin.PluginInfo.Enabled)
|
if (plugin.PluginInfo.Enabled)
|
||||||
_logger.Debug("Successfully enabled plugin {pluginInfo}", plugin.PluginInfo);
|
_logger.Debug("Successfully enabled plugin {pluginInfo}", plugin.PluginInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,10 +350,7 @@ namespace Artemis.Core.Services
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public PluginInfo GetPluginInfo(Plugin plugin)
|
public PluginInfo GetPluginInfo(Plugin plugin)
|
||||||
{
|
{
|
||||||
lock (_plugins)
|
return _plugins.FirstOrDefault(p => p.Instance == plugin);
|
||||||
{
|
|
||||||
return _plugins.FirstOrDefault(p => p.Instance == plugin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -366,10 +362,7 @@ namespace Artemis.Core.Services
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public List<T> GetPluginsOfType<T>() where T : Plugin
|
public List<T> GetPluginsOfType<T>() where T : Plugin
|
||||||
{
|
{
|
||||||
lock (_plugins)
|
return _plugins.Where(p => p.Enabled && p.Instance is T).Select(p => (T) p.Instance).ToList();
|
||||||
{
|
|
||||||
return _plugins.Where(p => p.Enabled && p.Instance is T).Select(p => (T) p.Instance).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin GetDevicePlugin(IRGBDevice rgbDevice)
|
public Plugin GetDevicePlugin(IRGBDevice rgbDevice)
|
||||||
@ -393,7 +386,7 @@ namespace Artemis.Core.Services
|
|||||||
Directory.CreateDirectory(pluginDirectory.FullName);
|
Directory.CreateDirectory(pluginDirectory.FullName);
|
||||||
|
|
||||||
builtInPluginDirectory.CopyFilesRecursively(pluginDirectory);
|
builtInPluginDirectory.CopyFilesRecursively(pluginDirectory);
|
||||||
if (createLockFile)
|
if (createLockFile)
|
||||||
File.Create(Path.Combine(pluginDirectory.FullName, "artemis.lock")).Close();
|
File.Create(Path.Combine(pluginDirectory.FullName, "artemis.lock")).Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -60,12 +60,13 @@ namespace Artemis.UI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (StartupArguments.Contains("-autorun"))
|
if (StartupArguments.Contains("--autorun"))
|
||||||
{
|
{
|
||||||
logger.Information("Sleeping for 15 seconds on auto run to allow applications like iCUE and LGS to start");
|
logger.Information("Sleeping for 15 seconds on auto run to allow applications like iCUE and LGS to start");
|
||||||
await Task.Delay(TimeSpan.FromSeconds(15));
|
await Task.Delay(TimeSpan.FromSeconds(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_core.StartupArguments = StartupArguments;
|
||||||
_core.Initialize();
|
_core.Initialize();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@ -33,14 +33,13 @@ namespace Artemis.UI.DataModelVisualization
|
|||||||
foreach (var item in List)
|
foreach (var item in List)
|
||||||
{
|
{
|
||||||
DataModelVisualizationViewModel child;
|
DataModelVisualizationViewModel child;
|
||||||
if (Children.Count < index )
|
if (Children.Count < index)
|
||||||
{
|
{
|
||||||
child = CreateChild(item);
|
child = CreateChild(item);
|
||||||
Children.Add(child);
|
Children.Add(child);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: This wont fly when mixing DataModels and DataModelProperties
|
|
||||||
child = Children[index];
|
child = Children[index];
|
||||||
child.Model = item;
|
child.Model = item;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,7 +211,7 @@ namespace Artemis.UI.Screens.Settings
|
|||||||
if (File.Exists(autoRunFile))
|
if (File.Exists(autoRunFile))
|
||||||
File.Delete(autoRunFile);
|
File.Delete(autoRunFile);
|
||||||
if (StartWithWindows)
|
if (StartWithWindows)
|
||||||
ShortcutUtilities.Create(autoRunFile, executableFile, "-autorun", new FileInfo(executableFile).DirectoryName, "Artemis", "", "");
|
ShortcutUtilities.Create(autoRunFile, executableFile, "--autorun", new FileInfo(executableFile).DirectoryName, "Artemis", "", "");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace Artemis.UI.Screens
|
|||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
CanShowRootViewModel = true;
|
CanShowRootViewModel = true;
|
||||||
|
|
||||||
var autoRunning = Bootstrapper.StartupArguments.Contains("-autorun");
|
var autoRunning = Bootstrapper.StartupArguments.Contains("--autorun");
|
||||||
var showOnAutoRun = settingsService.GetSetting("UI.ShowOnStartup", true).Value;
|
var showOnAutoRun = settingsService.GetSetting("UI.ShowOnStartup", true).Value;
|
||||||
if (!autoRunning || showOnAutoRun)
|
if (!autoRunning || showOnAutoRun)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.Plugins.Abstract;
|
using Artemis.Core.Plugins.Abstract;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
|
using Microsoft.Win32;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Devices.Corsair;
|
using RGB.NET.Devices.Corsair;
|
||||||
|
|
||||||
@ -22,6 +24,21 @@ namespace Artemis.Plugins.Devices.Corsair
|
|||||||
RGB.NET.Devices.Corsair.CorsairDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "CUESDK.x64_2017.dll"));
|
RGB.NET.Devices.Corsair.CorsairDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "CUESDK.x64_2017.dll"));
|
||||||
RGB.NET.Devices.Corsair.CorsairDeviceProvider.PossibleX86NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x86", "CUESDK_2017.dll"));
|
RGB.NET.Devices.Corsair.CorsairDeviceProvider.PossibleX86NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x86", "CUESDK_2017.dll"));
|
||||||
_rgbService.AddDeviceProvider(RgbDeviceProvider);
|
_rgbService.AddDeviceProvider(RgbDeviceProvider);
|
||||||
|
|
||||||
|
SystemEvents.PowerModeChanged += SystemEventsOnPowerModeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SystemEventsOnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
|
||||||
|
{
|
||||||
|
// This may be required for some device providers
|
||||||
|
// if (e.Mode == PowerModes.Resume)
|
||||||
|
// {
|
||||||
|
// Task.Run(async () =>
|
||||||
|
// {
|
||||||
|
// await Task.Delay(5000);
|
||||||
|
// RGB.NET.Devices.Corsair.CorsairDeviceProvider.Instance.Initialize();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,6 +31,8 @@ namespace Artemis.Plugins.Modules.General
|
|||||||
|
|
||||||
DataModel.IntsList[0] = _rand.Next();
|
DataModel.IntsList[0] = _rand.Next();
|
||||||
DataModel.IntsList[2] = _rand.Next();
|
DataModel.IntsList[2] = _rand.Next();
|
||||||
|
|
||||||
|
base.Update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EnablePlugin()
|
public override void EnablePlugin()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user