mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-20 23:07:43 +01:00
Cleanup TaskSchedulerWidget and ensure color is always popped
This commit is contained in:
parent
8c26d67739
commit
5fe6df3887
1 changed files with 16 additions and 29 deletions
|
|
@ -4,7 +4,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
@ -35,7 +34,7 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
private CancellationTokenSource taskSchedulerCancelSource = new();
|
private CancellationTokenSource taskSchedulerCancelSource = new();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string[]? CommandShortcuts { get; init; } = { "tasksched", "taskscheduler" };
|
public string[]? CommandShortcuts { get; init; } = ["tasksched", "taskscheduler"];
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string DisplayName { get; init; } = "Task Scheduler";
|
public string DisplayName { get; init; } = "Task Scheduler";
|
||||||
|
|
@ -266,8 +265,7 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
|
|
||||||
ImGui.Text($"{this.downloadState.Downloaded:##,###}/{this.downloadState.Total:##,###} ({this.downloadState.Percentage:0.00}%)");
|
ImGui.Text($"{this.downloadState.Downloaded:##,###}/{this.downloadState.Total:##,###} ({this.downloadState.Percentage:0.00}%)");
|
||||||
|
|
||||||
using var disabled =
|
using var disabled = ImRaii.Disabled(this.downloadTask?.IsCompleted is false || this.localPath[0] == 0);
|
||||||
ImRaii.Disabled(this.downloadTask?.IsCompleted is false || this.localPath[0] == 0);
|
|
||||||
ImGui.AlignTextToFramePadding();
|
ImGui.AlignTextToFramePadding();
|
||||||
ImGui.Text("Download"u8);
|
ImGui.Text("Download"u8);
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
@ -388,27 +386,19 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
if (task.Task == null)
|
if (task.Task == null)
|
||||||
subTime = task.FinishTime;
|
subTime = task.FinishTime;
|
||||||
|
|
||||||
switch (task.Status)
|
using var pushedColor = task.Status switch
|
||||||
{
|
{
|
||||||
case TaskStatus.Created:
|
TaskStatus.Created or TaskStatus.WaitingForActivation or TaskStatus.WaitingToRun
|
||||||
case TaskStatus.WaitingForActivation:
|
=> ImRaii.PushColor(ImGuiCol.Header, ImGuiColors.DalamudGrey),
|
||||||
case TaskStatus.WaitingToRun:
|
TaskStatus.Running or TaskStatus.WaitingForChildrenToComplete
|
||||||
ImGui.PushStyleColor(ImGuiCol.Header, ImGuiColors.DalamudGrey);
|
=> ImRaii.PushColor(ImGuiCol.Header, ImGuiColors.ParsedBlue),
|
||||||
break;
|
TaskStatus.RanToCompletion
|
||||||
case TaskStatus.Running:
|
=> ImRaii.PushColor(ImGuiCol.Header, ImGuiColors.ParsedGreen),
|
||||||
case TaskStatus.WaitingForChildrenToComplete:
|
TaskStatus.Canceled or TaskStatus.Faulted
|
||||||
ImGui.PushStyleColor(ImGuiCol.Header, ImGuiColors.ParsedBlue);
|
=> ImRaii.PushColor(ImGuiCol.Header, ImGuiColors.DalamudRed),
|
||||||
break;
|
|
||||||
case TaskStatus.RanToCompletion:
|
_ => throw new ArgumentOutOfRangeException(),
|
||||||
ImGui.PushStyleColor(ImGuiCol.Header, ImGuiColors.ParsedGreen);
|
};
|
||||||
break;
|
|
||||||
case TaskStatus.Canceled:
|
|
||||||
case TaskStatus.Faulted:
|
|
||||||
ImGui.PushStyleColor(ImGuiCol.Header, ImGuiColors.DalamudRed);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.CollapsingHeader($"#{task.Id} - {task.Status} {(subTime - task.StartTime).TotalMilliseconds}ms###task{i}"))
|
if (ImGui.CollapsingHeader($"#{task.Id} - {task.Status} {(subTime - task.StartTime).TotalMilliseconds}ms###task{i}"))
|
||||||
{
|
{
|
||||||
|
|
@ -418,8 +408,7 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cancelFunc =
|
var cancelFunc = typeof(Task).GetMethod("InternalCancel", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
typeof(Task).GetMethod("InternalCancel", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
cancelFunc?.Invoke(task, null);
|
cancelFunc?.Invoke(task, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -430,7 +419,7 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
|
|
||||||
ImGuiHelpers.ScaledDummy(10);
|
ImGuiHelpers.ScaledDummy(10);
|
||||||
|
|
||||||
ImGui.Text(task.StackTrace?.ToString());
|
ImGui.Text(task.StackTrace?.ToString() ?? "Null StackTrace");
|
||||||
|
|
||||||
if (task.Exception != null)
|
if (task.Exception != null)
|
||||||
{
|
{
|
||||||
|
|
@ -443,8 +432,6 @@ internal class TaskSchedulerWidget : IDataWindowWidget
|
||||||
{
|
{
|
||||||
task.IsBeingViewed = false;
|
task.IsBeingViewed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PopStyleColor(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fileDialogManager.Draw();
|
this.fileDialogManager.Draw();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue