Browse Source

Added an additional check case for StateTransitionTransaction to skip any behaviour if the transaction was never changed

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
476ad69212
2 changed files with 14 additions and 2 deletions
  1. +2
    -0
      IPA.Loader/Loader/PluginManager.cs
  2. +12
    -2
      IPA.Loader/Loader/StateTransitionTransaction.cs

+ 2
- 0
IPA.Loader/Loader/PluginManager.cs View File

@ -82,6 +82,8 @@ namespace IPA.Loader
internal static Task CommitTransaction(StateTransitionTransaction transaction)
{
if (!transaction.HasStateChanged) return TaskEx.WhenAll();
if (!UnityGame.OnMainThread)
return UnityMainThreadTaskScheduler.Factory.StartNew(() => CommitTransaction(transaction)).Unwrap();


+ 12
- 2
IPA.Loader/Loader/StateTransitionTransaction.cs View File

@ -15,6 +15,7 @@ namespace IPA.Loader
private readonly HashSet<PluginMetadata> currentlyDisabled;
private readonly HashSet<PluginMetadata> toEnable = new HashSet<PluginMetadata>();
private readonly HashSet<PluginMetadata> toDisable = new HashSet<PluginMetadata>();
private bool stateChanged = false;
internal StateTransitionTransaction(IEnumerable<PluginMetadata> enabled, IEnumerable<PluginMetadata> disabled)
{
@ -29,7 +30,14 @@ namespace IPA.Loader
/// <exception cref="ObjectDisposedException">if this object has been disposed</exception>
public bool WillNeedRestart
=> ThrowIfDisposed<bool>()
|| toEnable.Concat(toDisable).Any(m => m.RuntimeOptions != RuntimeOptions.DynamicInit);
|| (stateChanged && toEnable.Concat(toDisable).Any(m => m.RuntimeOptions != RuntimeOptions.DynamicInit));
/// <summary>
/// Gets whether or not the current state has changed.
/// </summary>
/// <value><see langword="true"/> if the current state of the transaction is different from its construction, <see langword="false"/> otherwise</value>
/// <exception cref="ObjectDisposedException">if this object has been disposed</exception>
public bool HasStateChanged => ThrowIfDisposed<bool>() || stateChanged;
internal IEnumerable<PluginMetadata> CurrentlyEnabled => currentlyEnabled;
internal IEnumerable<PluginMetadata> CurrentlyDisabled => currentlyDisabled;
@ -41,7 +49,7 @@ namespace IPA.Loader
/// </summary>
/// <exception cref="ObjectDisposedException">if this object has been disposed</exception>
public IEnumerable<PluginMetadata> EnabledPlugins
=> ThrowIfDisposed<IEnumerable<PluginMetadata>>() ?? DisabledPluginsInternal;
=> ThrowIfDisposed<IEnumerable<PluginMetadata>>() ?? EnabledPluginsInternal;
private IEnumerable<PluginMetadata> EnabledPluginsInternal => currentlyEnabled.Except(toDisable).Concat(toEnable);
/// <summary>
/// Gets a list of plugins that are disabled according to this transaction's current state.
@ -139,6 +147,7 @@ namespace IPA.Loader
toDisable.Remove(meta);
toEnable.Add(meta);
stateChanged = true;
return true;
}
@ -195,6 +204,7 @@ namespace IPA.Loader
toDisable.Add(meta);
toEnable.Remove(meta);
stateChanged = true;
return true;
}


Loading…
Cancel
Save