feat: give dev plugins more leeway regarding unload errors

This commit is contained in:
goaaats 2023-01-08 00:32:24 +01:00
parent bb6109db45
commit 6ea7273e04
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 26 additions and 8 deletions

View file

@ -2222,7 +2222,7 @@ internal class PluginInstallerWindow : Window, IDisposable
StyleModelV1.DalamudStandard.Push();
if (plugin.State == PluginState.UnloadError)
if (plugin.State == PluginState.UnloadError && !plugin.IsDev)
{
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);

View file

@ -138,9 +138,9 @@ internal class LocalDevPlugin : LocalPlugin, IDisposable
return;
}
if (this.State != PluginState.Loaded && this.State != PluginState.LoadError)
if (this.State != PluginState.Loaded && this.State != PluginState.LoadError && this.State != PluginState.UnloadError)
{
Log.Debug($"Skipping reload of {this.Name}, state ({this.State}) is not {PluginState.Loaded} nor {PluginState.LoadError}.");
Log.Debug($"Skipping reload of {this.Name}, state ({this.State}) is not {PluginState.Loaded}, {PluginState.LoadError} or {PluginState.UnloadError}.");
return;
}
@ -148,6 +148,12 @@ internal class LocalDevPlugin : LocalPlugin, IDisposable
try
{
if (this.State == PluginState.UnloadError)
{
Log.Warning($"{this.Manifest.Author}: TAKE CARE!!! You need to fix your unload error, and restart the game - your plugin might be in an inconsistent state.");
Log.Warning("Reloading anyway, as this is a dev plugin, but you might encounter unexpected results.");
}
await this.ReloadAsync();
notificationManager.AddNotification($"The DevPlugin '{this.Name} was reloaded successfully.", "Plugin reloaded!", NotificationType.Success);
}

View file

@ -15,7 +15,6 @@ using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Exceptions;
using Dalamud.Plugin.Internal.Loader;
using Dalamud.Utility;
using Dalamud.Utility.Signatures;
namespace Dalamud.Plugin.Internal.Types;
@ -305,8 +304,13 @@ internal class LocalPlugin : IDisposable
throw new InvalidPluginOperationException(
$"Unable to load {this.Name}, load previously faulted, unload first");
case PluginState.UnloadError:
if (!this.IsDev)
{
throw new InvalidPluginOperationException(
$"Unable to load {this.Name}, unload previously faulted, restart Dalamud");
}
break;
case PluginState.Unloaded:
break;
case PluginState.Loading:
@ -471,8 +475,13 @@ internal class LocalPlugin : IDisposable
case PluginState.Unloaded:
throw new InvalidPluginOperationException($"Unable to unload {this.Name}, already unloaded");
case PluginState.UnloadError:
if (!this.IsDev)
{
throw new InvalidPluginOperationException(
$"Unable to unload {this.Name}, unload previously faulted, restart Dalamud");
}
break;
case PluginState.Loaded:
case PluginState.LoadError:
break;
@ -531,7 +540,10 @@ internal class LocalPlugin : IDisposable
/// <returns>A task.</returns>
public async Task ReloadAsync()
{
// Don't unload if we're a dev plugin and have an unload error, this is a bad idea but whatever
if (this.IsDev && this.State != PluginState.UnloadError)
await this.UnloadAsync(true);
await this.LoadAsync(PluginLoadReason.Reload, true);
}