Modules - Added IsActivatedOverride which indicates exactly that

Core - During creation ensure all local users can access the data folder
Core - Wrap exceptions during module enable/disable in PluginExceptions
This commit is contained in:
SpoinkyNL committed 2020-08-26 00:26:29 +02:00
1 parent 6672b1d6b0
commit cf87410a50
4 files changed
+65 -16

No files matched your search

+2 -4
View File
@@ -1,4 +1,6 @@
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Settings;
using Artemis.Core.Services.Interfaces;
@@ -44,10 +46,6 @@ namespace Artemis.Core.Ninject
Kernel.Bind<LiteRepository>().ToMethod(t =>
{
// Ensure the data folder exists
if (!Directory.Exists(Constants.DataFolder))
Directory.CreateDirectory(Constants.DataFolder);
try
{
return new LiteRepository(Constants.ConnectionString);
@@ -91,6 +91,12 @@ namespace Artemis.Core.Plugins.Modules
/// </summary>
public bool IsActivated { get; internal set; }
/// <summary>
/// Gets whether this module's activation was due to an override, can only be true if <see cref="IsActivated" /> is
/// true
/// </summary>
public bool IsActivatedOverride { get; set; }
/// <summary>
/// A list of activation requirements
/// <para>Note: if empty the module is always activated</para>
@@ -182,6 +188,7 @@ namespace Artemis.Core.Plugins.Modules
if (IsActivated)
return;
IsActivatedOverride = isOverride;
ModuleActivated(isOverride);
IsActivated = true;
}
@@ -191,6 +198,7 @@ namespace Artemis.Core.Plugins.Modules
if (!IsActivated)
return;
IsActivatedOverride = false;
IsActivated = false;
ModuleDeactivated(isOverride);
}
+25 -8
View File
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Timers;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Modules;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
@@ -156,20 +157,36 @@ namespace Artemis.Core.Services
private async Task ActivateModule(Module module, bool isOverride)
{
module.Activate(isOverride);
try
{
module.Activate(isOverride);
// If this is a profile module, activate the last active profile after module activation
if (module is ProfileModule profileModule)
await _profileService.ActivateLastProfileAnimated(profileModule);
// If this is a profile module, activate the last active profile after module activation
if (module is ProfileModule profileModule)
await _profileService.ActivateLastProfileAnimated(profileModule);
}
catch (Exception e)
{
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to activate module and last profile.", e), "Failed to activate module and last profile");
throw;
}
}
private async Task DeactivateModule(Module module, bool isOverride)
{
// If this is a profile module, activate the last active profile after module activation
if (module.IsActivated && module is ProfileModule profileModule)
await profileModule.ChangeActiveProfileAnimated(null, null);
try
{
// If this is a profile module, activate the last active profile after module activation
if (module.IsActivated && module is ProfileModule profileModule)
await profileModule.ChangeActiveProfileAnimated(null, null);
module.Deactivate(isOverride);
module.Deactivate(isOverride);
}
catch (Exception e)
{
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to deactivate module and last profile.", e), "Failed to deactivate module and last profile");
throw;
}
}
private void PopulatePriorities()