Skip to content

Commit

Permalink
feat: allow copying from download history tab too
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Apr 17, 2024
1 parent e68ae91 commit c721a8a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
29 changes: 29 additions & 0 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,35 @@ internal Task OpenModInPenumbra() {
});
}

internal string? GetErrorInformation() {
if (this.Error is not { } error) {
return null;
}

var sb = new StringBuilder();
sb.Append("```\n");
var i = 0;
foreach (var ex in error.AsEnumerable()) {
if (i != 0) {
sb.Append('\n');
}

i += 1;

sb.Append($"Error type: {ex.GetType().FullName}\n");
sb.Append($" Message: {ex.Message}\n");
sb.Append($" HResult: 0x{unchecked((uint) ex.HResult):X8}\n");
if (ex.StackTrace is { } trace) {
sb.Append(trace);
sb.Append('\n');
}
}

sb.Append("```");

return sb.ToString();
}

internal struct Measurement {
internal long Ticks;
internal uint Data;
Expand Down
25 changes: 3 additions & 22 deletions Ui/NotificationProgressManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,10 @@ private State UpdateNotif(IActiveNotification notif, DownloadTask task) {
? "Copied!"
: "Copy error information";
if (ImGui.Button($"{label}###copy-error-information", new Vector2(widthAvail, 0))) {
var sb = new StringBuilder();
sb.Append("```\n");
var i = 0;
foreach (var ex in error.AsEnumerable()) {
if (i != 0) {
sb.Append('\n');
}
i += 1;
sb.Append($"Error type: {ex.GetType().FullName}\n");
sb.Append($" Message: {ex.Message}\n");
sb.Append($" HResult: 0x{unchecked((uint) ex.HResult):X8}\n");
if (ex.StackTrace is { } trace) {
sb.Append(trace);
sb.Append('\n');
}
if (task.GetErrorInformation() is { } info) {
ImGui.SetClipboardText(info);
copiedTimer.Start();
}
sb.Append("```");
ImGui.SetClipboardText(sb.ToString());
copiedTimer.Start();
}
};
}
Expand Down
17 changes: 15 additions & 2 deletions Ui/Tabs/DownloadHistory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.Internal.Notifications;
using Heliosphere.Util;
using ImGuiNET;

Expand All @@ -17,6 +19,7 @@ internal void Draw() {
}

ImGui.TextUnformatted("Click to remove from history.");
ImGui.TextUnformatted("Right-click on errored downloads to copy error information.");

using var guard = this.Plugin.Downloads.Wait(0);
var downloads = guard?.Data ?? [];
Expand All @@ -41,11 +44,21 @@ internal void Draw() {
$"{packageName}{info.State.Name()}: {info.StateData} / {info.StateDataMax}"
);

if (!info.State.IsDone() || !ImGui.IsItemClicked()) {
if (!info.State.IsDone()) {
continue;
}

toRemove = i;
if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) {
toRemove = i;
} else if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) {
if (task.GetErrorInformation() is { } errorInfo) {
ImGui.SetClipboardText(errorInfo);
this.Plugin.NotificationManager.AddNotification(new Notification {
Type = NotificationType.Info,
Content = "Error information copied to clipboard.",
});
}
}
}

if (toRemove > -1) {
Expand Down

0 comments on commit c721a8a

Please sign in to comment.