fix(PluginInstallerWindow): use task for single update, correct error handling

This commit is contained in:
goat 2021-07-15 04:01:26 +02:00
parent 112833be8b
commit 0cb0bff714
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 30 additions and 7 deletions

View file

@ -787,7 +787,22 @@ namespace Dalamud.Interface.Internal.Windows
if (ImGuiComponents.IconButton(FontAwesomeIcon.Download)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Download))
{ {
this.dalamud.PluginManager.UpdateSinglePlugin(update, false); this.installStatus = OperationStatus.InProgress;
Task.Run(() => this.dalamud.PluginManager.UpdateSinglePlugin(update, false))
.ContinueWith(task =>
{
// There is no need to set as Complete for an individual plugin installation
this.installStatus = OperationStatus.Idle;
var errorMessage = Locs.ErrorModal_SingleUpdateFail(update.UpdateManifest.Name);
this.DisplayErrorContinuation(task, errorMessage);
if (!task.Result.WasUpdated)
{
ShowErrorModal(errorMessage);
}
});
} }
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
@ -986,7 +1001,7 @@ namespace Dalamud.Interface.Internal.Windows
{ {
if (task.IsFaulted) if (task.IsFaulted)
{ {
this.errorModalMessage = state as string; var errorModalMessage = state as string;
foreach (var ex in task.Exception.InnerExceptions) foreach (var ex in task.Exception.InnerExceptions)
{ {
@ -995,7 +1010,7 @@ namespace Dalamud.Interface.Internal.Windows
Log.Error(ex, "Plugin installer threw an error"); Log.Error(ex, "Plugin installer threw an error");
#if DEBUG #if DEBUG
if (!string.IsNullOrEmpty(ex.Message)) if (!string.IsNullOrEmpty(ex.Message))
this.errorModalMessage += $"\n\n{ex.Message}"; errorModalMessage += $"\n\n{ex.Message}";
#endif #endif
} }
else else
@ -1003,13 +1018,12 @@ namespace Dalamud.Interface.Internal.Windows
Log.Error(ex, "Plugin installer threw an unexpected error"); Log.Error(ex, "Plugin installer threw an unexpected error");
#if DEBUG #if DEBUG
if (!string.IsNullOrEmpty(ex.Message)) if (!string.IsNullOrEmpty(ex.Message))
this.errorModalMessage += $"\n\n{ex.Message}"; errorModalMessage += $"\n\n{ex.Message}";
#endif #endif
} }
} }
this.errorModalDrawing = true; this.ShowErrorModal(errorModalMessage);
this.errorModalOnNextFrame = true;
return false; return false;
} }
@ -1017,6 +1031,13 @@ namespace Dalamud.Interface.Internal.Windows
return true; return true;
} }
private void ShowErrorModal(string message)
{
this.errorModalMessage = message;
this.errorModalDrawing = true;
this.errorModalOnNextFrame = true;
}
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements should appear in the correct order", Justification = "Disregard here")] [SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements should appear in the correct order", Justification = "Disregard here")]
private static class Locs private static class Locs
{ {
@ -1176,6 +1197,8 @@ namespace Dalamud.Interface.Internal.Windows
public static string ErrorModal_InstallFail(string name) => Loc.Localize("InstallerInstallFail", "Failed to install plugin {0}.").Format(name); public static string ErrorModal_InstallFail(string name) => Loc.Localize("InstallerInstallFail", "Failed to install plugin {0}.").Format(name);
public static string ErrorModal_SingleUpdateFail(string name) => Loc.Localize("InstallerSingleUpdateFail", "Failed to update plugin {0}.").Format(name);
public static string ErrorModal_EnableFail(string name) => Loc.Localize("InstallerEnableFail", "Failed to enable plugin {0}.").Format(name); public static string ErrorModal_EnableFail(string name) => Loc.Localize("InstallerEnableFail", "Failed to enable plugin {0}.").Format(name);
public static string ErrorModal_DisableFail(string name) => Loc.Localize("InstallerDisableFail", "Failed to disable plugin {0}.").Format(name); public static string ErrorModal_DisableFail(string name) => Loc.Localize("InstallerDisableFail", "Failed to disable plugin {0}.").Format(name);

View file

@ -635,7 +635,7 @@ namespace Dalamud.Plugin.Internal
{ {
InternalName = plugin.Manifest.InternalName, InternalName = plugin.Manifest.InternalName,
Name = plugin.Manifest.Name, Name = plugin.Manifest.Name,
Version = metadata.UseTesting ? metadata.UpdateManifest.TestingAssemblyVersion : metadata.UpdateManifest.AssemblyVersion Version = metadata.UseTesting ? metadata.UpdateManifest.TestingAssemblyVersion : metadata.UpdateManifest.AssemblyVersion,
}; };
if (dryRun) if (dryRun)