diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index b42275c4..06df93d5 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -208,9 +208,13 @@ namespace IPA.Loader var disabled = new Dictionary(); 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(); // changed is handled by transaction return result; @@ -250,23 +254,38 @@ namespace IPA.Loader /// the plugin that was disabled /// whether it needs a restart to take effect public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart); + /// + /// A delegate representing a state change event for any plugin. + /// + /// the representing the change + /// the plugins that were enabled in the change + /// the plugins that were disabled in the change + public delegate void OnAnyPluginsStateChangedDelegate(Task changeTask, IEnumerable enabled, IEnumerable disabled); /// - /// Called whenever a plugin is enabled. + /// Called whenever a plugin is enabled, before the plugin in question is enabled. /// public static event PluginEnableDelegate PluginEnabled; /// - /// Called whenever a plugin is disabled. + /// Called whenever a plugin is disabled, before the plugin in question is enabled. /// public static event PluginDisableDelegate PluginDisabled; /// - /// Called whenever any plugins have their state changed with the representing that state change. + /// Called whenever any plugins have their state changed at runtime with the representing that state change. /// /// /// Note that this is called on the Unity main thread, and cannot therefore block, as the /// provided represents operations that also run on the Unity main thread. /// public static event Action OnPluginsStateChanged; + /// + /// Called whenever any plugins, regardless of whether or not their change occurs during runtime, have their state changed. + /// + /// + /// Note that this is called on the Unity main thread, and cannot therefore block, as the + /// provided represents operations that also run on the Unity main thread. + /// + public static event OnAnyPluginsStateChangedDelegate OnAnyPluginsStateChanged; /// /// Gets a list of all enabled BSIPA plugins. Use instead of this. diff --git a/IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs b/IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs index 3bbc84fc..eb53fc92 100644 --- a/IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs +++ b/IPA.Loader/Utilities/Async/UnityMainThreadTaskScheduler.cs @@ -180,7 +180,7 @@ namespace IPA.Utilities.Async } /// - /// Queues a given to this scheduler. The must> be + /// Queues a given to this scheduler. The must be /// scheduled for this by the runtime. /// /// the to queue @@ -195,12 +195,8 @@ namespace IPA.Utilities.Async } /// - /// Rejects any attempts to execute a task inline. + /// Runs the task inline if the current thread is the Unity main thread. /// - /// - /// This task scheduler always runs its tasks on the thread that it manages, therefore it doesn't - /// make sense to run it inline. - /// /// the task to attempt to execute /// whether the task was previously queued to this scheduler ///