Browse Source

Changed when OnPluginsStateChanged is invoked, and added a new OnAnyPluginsStateChanged to take over where it had been

pull/44/head
Anairkoen Schno 4 years ago
parent
commit
0870f01df6
2 changed files with 25 additions and 10 deletions
  1. +23
    -4
      IPA.Loader/Loader/PluginManager.cs
  2. +2
    -6
      IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs

+ 23
- 4
IPA.Loader/Loader/PluginManager.cs View File

@ -208,9 +208,13 @@ namespace IPA.Loader
var disabled = new Dictionary<PluginExecutor, Task>(); var disabled = new Dictionary<PluginExecutor, Task>();
result = TaskEx.WhenAll(disableStructure.Select(d => Disable(d, disabled))); result = TaskEx.WhenAll(disableStructure.Select(d => Disable(d, disabled)));
OnPluginsStateChanged?.Invoke(result);
} }
OnAnyPluginsStateChanged?.Invoke(result, toEnable, toDisable);
// if there are any that are capable of enabling/disabling at runtime, run event handler
if (toEnable.Concat(toDisable).Any(m => m.RuntimeOptions == RuntimeOptions.DynamicInit))
OnPluginsStateChanged?.Invoke(result);
//DisabledConfig.Instance.Changed(); //DisabledConfig.Instance.Changed();
// changed is handled by transaction // changed is handled by transaction
return result; return result;
@ -250,23 +254,38 @@ namespace IPA.Loader
/// <param name="plugin">the plugin that was disabled</param> /// <param name="plugin">the plugin that was disabled</param>
/// <param name="needsRestart">whether it needs a restart to take effect</param> /// <param name="needsRestart">whether it needs a restart to take effect</param>
public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart); public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart);
/// <summary>
/// A delegate representing a state change event for any plugin.
/// </summary>
/// <param name="changeTask">the <see cref="Task"/> representing the change</param>
/// <param name="enabled">the plugins that were enabled in the change</param>
/// <param name="disabled">the plugins that were disabled in the change</param>
public delegate void OnAnyPluginsStateChangedDelegate(Task changeTask, IEnumerable<PluginMetadata> enabled, IEnumerable<PluginMetadata> disabled);
/// <summary> /// <summary>
/// Called whenever a plugin is enabled.
/// Called whenever a plugin is enabled, before the plugin in question is enabled.
/// </summary> /// </summary>
public static event PluginEnableDelegate PluginEnabled; public static event PluginEnableDelegate PluginEnabled;
/// <summary> /// <summary>
/// Called whenever a plugin is disabled.
/// Called whenever a plugin is disabled, before the plugin in question is enabled.
/// </summary> /// </summary>
public static event PluginDisableDelegate PluginDisabled; public static event PluginDisableDelegate PluginDisabled;
/// <summary> /// <summary>
/// Called whenever any plugins have their state changed with the <see cref="Task"/> representing that state change.
/// Called whenever any plugins have their state changed at runtime with the <see cref="Task"/> representing that state change.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/> /// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
/// provided represents operations that also run on the Unity main thread. /// provided represents operations that also run on the Unity main thread.
/// </remarks> /// </remarks>
public static event Action<Task> OnPluginsStateChanged; public static event Action<Task> OnPluginsStateChanged;
/// <summary>
/// Called whenever any plugins, regardless of whether or not their change occurs during runtime, have their state changed.
/// </summary>
/// <remarks>
/// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
/// provided represents operations that also run on the Unity main thread.
/// </remarks>
public static event OnAnyPluginsStateChangedDelegate OnAnyPluginsStateChanged;
/// <summary> /// <summary>
/// Gets a list of all enabled BSIPA plugins. Use <see cref="EnabledPlugins"/> instead of this. /// Gets a list of all enabled BSIPA plugins. Use <see cref="EnabledPlugins"/> instead of this.


+ 2
- 6
IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs View File

@ -180,7 +180,7 @@ namespace IPA.Utilities.Async
} }
/// <summary> /// <summary>
/// Queues a given <see cref="Task"/> to this scheduler. The <see cref="Task"/> <i>must></i> be
/// Queues a given <see cref="Task"/> to this scheduler. The <see cref="Task"/> <i>must</i> be
/// scheduled for this <see cref="TaskScheduler"/> by the runtime. /// scheduled for this <see cref="TaskScheduler"/> by the runtime.
/// </summary> /// </summary>
/// <param name="task">the <see cref="Task"/> to queue</param> /// <param name="task">the <see cref="Task"/> to queue</param>
@ -195,12 +195,8 @@ namespace IPA.Utilities.Async
} }
/// <summary> /// <summary>
/// Rejects any attempts to execute a task inline.
/// Runs the task inline if the current thread is the Unity main thread.
/// </summary> /// </summary>
/// <remarks>
/// This task scheduler <i>always</i> runs its tasks on the thread that it manages, therefore it doesn't
/// make sense to run it inline.
/// </remarks>
/// <param name="task">the task to attempt to execute</param> /// <param name="task">the task to attempt to execute</param>
/// <param name="taskWasPreviouslyQueued">whether the task was previously queued to this scheduler</param> /// <param name="taskWasPreviouslyQueued">whether the task was previously queued to this scheduler</param>
/// <returns><see langword="false"/></returns> /// <returns><see langword="false"/></returns>


Loading…
Cancel
Save