Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show detailed statuses in task queue #1172

Merged
merged 4 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/PageQueue.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="8,0,0,0" >
<emoji:TextBlock Text="{Binding Info.Title, StringFormat=Title: {0}}" TextWrapping="Wrap" Foreground="{DynamicResource AppText}"></emoji:TextBlock>
<TextBlock Text="{Binding TaskType, StringFormat=Task Type: {0}}" Foreground="{DynamicResource AppText}"></TextBlock>
<TextBlock Text="{Binding Status, StringFormat=Status: {0}, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" Foreground="{DynamicResource AppText}"></TextBlock>
<TextBlock Text="{Binding DisplayStatus, StringFormat=Status: {0}, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" Foreground="{DynamicResource AppText}"></TextBlock>
<StackPanel Orientation="Horizontal" Margin="1,1,0,1">
<Button Content="{lex:Loc TaskCancel}" Margin="0,0,4,0" MinWidth="60" Height="28" FontSize="12" Click="BtnCancelTask_Click" IsEnabled="{Binding CanCancel}" Background="{DynamicResource ActionButtonBackground}" Foreground="{DynamicResource ActionButtonText}" BorderBrush="{DynamicResource ActionButtonBorder}" />
<Button Visibility="{Binding Exception.Visibility}" Content="{lex:Loc TaskErrorButton}" Margin="0,0,4,0" MinWidth="60" Height="28" FontSize="12" Click="BtnTaskError_Click" Background="{DynamicResource ActionButtonBackground}" Foreground="{DynamicResource ActionButtonText}" BorderBrush="{DynamicResource ActionButtonBorder}" />
Expand Down
22 changes: 12 additions & 10 deletions TwitchDownloaderWPF/PageQueue.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace TwitchDownloaderWPF
public partial class PageQueue : Page
{
public static readonly object taskLock = new object();
public static ObservableCollection<ITwitchTask> taskList { get; set; } = new ObservableCollection<ITwitchTask>();
BackgroundWorker taskManager = new BackgroundWorker();
public static ObservableCollection<ITwitchTask> taskList { get; } = new ObservableCollection<ITwitchTask>();
private static readonly BackgroundWorker taskManager = new BackgroundWorker();

public PageQueue()
{
Expand All @@ -34,7 +34,7 @@ public PageQueue()
taskManager.RunWorkerAsync();
}

private void TaskManager_DoWork(object sender, DoWorkEventArgs e)
private static void TaskManager_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
Expand All @@ -47,10 +47,13 @@ private void TaskManager_DoWork(object sender, DoWorkEventArgs e)
int currentChat = 0;
int currentRender = 0;

foreach (var task in taskList)
lock (taskLock)
{
if (task.Status == TwitchTaskStatus.Running)
foreach (var task in taskList)
{
if (task.Status is not TwitchTaskStatus.Running)
continue;

switch (task)
{
case VodDownloadTask:
Expand All @@ -70,12 +73,12 @@ private void TaskManager_DoWork(object sender, DoWorkEventArgs e)
break;
}
}
}

foreach (var task in taskList)
{
if (task.CanRun())
foreach (var task in taskList)
{
if (!task.CanRun())
continue;

switch (task)
{
case VodDownloadTask when currentVod < maxVod:
Expand All @@ -99,7 +102,6 @@ private void TaskManager_DoWork(object sender, DoWorkEventArgs e)
task.RunAsync();
break;
}
continue;
}
}

Expand Down
12 changes: 10 additions & 2 deletions TwitchDownloaderWPF/TwitchTasks/ChatDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TwitchDownloaderWPF.TwitchTasks
{
class ChatDownloadTask : ITwitchTask
internal class ChatDownloadTask : ITwitchTask
{
public TaskData Info { get; set; } = new TaskData();

Expand All @@ -28,6 +28,13 @@ public TwitchTaskStatus Status
private set => SetField(ref _status, value);
}

private string _displayStatus;
public string DisplayStatus
{
get => _displayStatus;
private set => SetField(ref _displayStatus, value);
}

public ChatDownloadOptions DownloadOptions { get; init; }
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public ITwitchTask DependantTask { get; set; }
Expand Down Expand Up @@ -77,6 +84,7 @@ public bool CanRun()
public void ChangeStatus(TwitchTaskStatus newStatus)
{
Status = newStatus;
DisplayStatus = newStatus.ToString();

if (CanCancel && newStatus is TwitchTaskStatus.Canceled or TwitchTaskStatus.Failed or TwitchTaskStatus.Finished or TwitchTaskStatus.Stopping)
{
Expand All @@ -93,7 +101,7 @@ public async Task RunAsync()
return;
}

var progress = new WpfTaskProgress(i => Progress = i);
var progress = new WpfTaskProgress(i => Progress = i, s => DisplayStatus = s);
ChatDownloader downloader = new ChatDownloader(DownloadOptions, progress);
ChangeStatus(TwitchTaskStatus.Running);
try
Expand Down
12 changes: 10 additions & 2 deletions TwitchDownloaderWPF/TwitchTasks/ChatRenderTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TwitchDownloaderWPF.TwitchTasks
{
class ChatRenderTask : ITwitchTask
internal class ChatRenderTask : ITwitchTask
{
public TaskData Info { get; set; } = new TaskData();

Expand All @@ -28,6 +28,13 @@ public TwitchTaskStatus Status
private set => SetField(ref _status, value);
}

private string _displayStatus;
public string DisplayStatus
{
get => _displayStatus;
private set => SetField(ref _displayStatus, value);
}

public ChatRenderOptions DownloadOptions { get; init; }
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public ITwitchTask DependantTask { get; set; }
Expand Down Expand Up @@ -96,6 +103,7 @@ public bool CanRun()
public void ChangeStatus(TwitchTaskStatus newStatus)
{
Status = newStatus;
DisplayStatus = newStatus.ToString();

if (CanCancel && newStatus is TwitchTaskStatus.Canceled or TwitchTaskStatus.Failed or TwitchTaskStatus.Finished or TwitchTaskStatus.Stopping)
{
Expand All @@ -112,7 +120,7 @@ public async Task RunAsync()
return;
}

var progress = new WpfTaskProgress(i => Progress = i);
var progress = new WpfTaskProgress(i => Progress = i, s => DisplayStatus = s);
ChatRenderer renderer = new ChatRenderer(DownloadOptions, progress);
ChangeStatus(TwitchTaskStatus.Running);
try
Expand Down
12 changes: 10 additions & 2 deletions TwitchDownloaderWPF/TwitchTasks/ChatUpdateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TwitchDownloaderWPF.TwitchTasks
{
class ChatUpdateTask : ITwitchTask
internal class ChatUpdateTask : ITwitchTask
{
public TaskData Info { get; set; } = new TaskData();

Expand All @@ -28,6 +28,13 @@ public TwitchTaskStatus Status
private set => SetField(ref _status, value);
}

private string _displayStatus;
public string DisplayStatus
{
get => _displayStatus;
private set => SetField(ref _displayStatus, value);
}

public ChatUpdateOptions UpdateOptions { get; init; }
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public ITwitchTask DependantTask { get; set; }
Expand Down Expand Up @@ -77,6 +84,7 @@ public bool CanRun()
public void ChangeStatus(TwitchTaskStatus newStatus)
{
Status = newStatus;
DisplayStatus = newStatus.ToString();

if (CanCancel && newStatus is TwitchTaskStatus.Canceled or TwitchTaskStatus.Failed or TwitchTaskStatus.Finished or TwitchTaskStatus.Stopping)
{
Expand All @@ -93,7 +101,7 @@ public async Task RunAsync()
return;
}

var progress = new WpfTaskProgress(i => Progress = i);
var progress = new WpfTaskProgress(i => Progress = i, s => DisplayStatus = s);
ChatUpdater updater = new ChatUpdater(UpdateOptions, progress);
ChangeStatus(TwitchTaskStatus.Running);
try
Expand Down
12 changes: 10 additions & 2 deletions TwitchDownloaderWPF/TwitchTasks/ClipDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TwitchDownloaderWPF.TwitchTasks
{
class ClipDownloadTask : ITwitchTask
internal class ClipDownloadTask : ITwitchTask
{
public TaskData Info { get; set; } = new TaskData();

Expand All @@ -28,6 +28,13 @@ public TwitchTaskStatus Status
private set => SetField(ref _status, value);
}

private string _displayStatus;
public string DisplayStatus
{
get => _displayStatus;
private set => SetField(ref _displayStatus, value);
}

public ClipDownloadOptions DownloadOptions { get; init; }
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public ITwitchTask DependantTask { get; set; }
Expand Down Expand Up @@ -77,6 +84,7 @@ public bool CanRun()
public void ChangeStatus(TwitchTaskStatus newStatus)
{
Status = newStatus;
DisplayStatus = newStatus.ToString();

if (CanCancel && newStatus is TwitchTaskStatus.Canceled or TwitchTaskStatus.Failed or TwitchTaskStatus.Finished or TwitchTaskStatus.Stopping)
{
Expand All @@ -93,7 +101,7 @@ public async Task RunAsync()
return;
}

var progress = new WpfTaskProgress(i => Progress = i);
var progress = new WpfTaskProgress(i => Progress = i, s => DisplayStatus = s);
ClipDownloader downloader = new ClipDownloader(DownloadOptions, progress);
ChangeStatus(TwitchTaskStatus.Running);
try
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/TwitchTasks/ITwitchTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface ITwitchTask : INotifyPropertyChanged
TaskData Info { get; set; }
int Progress { get; }
TwitchTaskStatus Status { get; }
string DisplayStatus { get; }
CancellationTokenSource TokenSource { get; set; }
ITwitchTask DependantTask { get; set; }
string TaskType { get; }
Expand Down
12 changes: 10 additions & 2 deletions TwitchDownloaderWPF/TwitchTasks/VodDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TwitchDownloaderWPF.TwitchTasks
{
class VodDownloadTask : ITwitchTask
internal class VodDownloadTask : ITwitchTask
{
public TaskData Info { get; set; } = new TaskData();

Expand All @@ -28,6 +28,13 @@ public TwitchTaskStatus Status
private set => SetField(ref _status, value);
}

private string _displayStatus;
public string DisplayStatus
{
get => _displayStatus;
private set => SetField(ref _displayStatus, value);
}

public VideoDownloadOptions DownloadOptions { get; init; }
public CancellationTokenSource TokenSource { get; set; } = new CancellationTokenSource();
public ITwitchTask DependantTask { get; set; }
Expand Down Expand Up @@ -77,6 +84,7 @@ public bool CanRun()
public void ChangeStatus(TwitchTaskStatus newStatus)
{
Status = newStatus;
DisplayStatus = newStatus.ToString();

if (CanCancel && newStatus is TwitchTaskStatus.Canceled or TwitchTaskStatus.Failed or TwitchTaskStatus.Finished or TwitchTaskStatus.Stopping)
{
Expand All @@ -93,7 +101,7 @@ public async Task RunAsync()
return;
}

var progress = new WpfTaskProgress(i => Progress = i);
var progress = new WpfTaskProgress(i => Progress = i, s => DisplayStatus = s);
VideoDownloader downloader = new VideoDownloader(DownloadOptions, progress);
ChangeStatus(TwitchTaskStatus.Running);
try
Expand Down
8 changes: 4 additions & 4 deletions TwitchDownloaderWPF/Utils/WpfTaskProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ internal class WpfTaskProgress : ITaskProgress
private readonly Action<string> _handleLog;
private readonly Action<string> _handleFfmpegLog;

public WpfTaskProgress(Action<int> handlePercent)
public WpfTaskProgress(Action<int> handlePercent, Action<string> handleStatus)
{
_handlePercent = handlePercent;
_handleStatus = null;
_handleStatus = handleStatus;
_handleLog = null;
_handleFfmpegLog = null;

Expand Down Expand Up @@ -145,14 +145,14 @@ public void LogInfo(string logMessage)
{
if ((_logLevel & LogLevel.Info) == 0) return;

_handleLog.Invoke(logMessage);
_handleLog?.Invoke(logMessage);
}

public void LogInfo(DefaultInterpolatedStringHandler logMessage)
{
if ((_logLevel & LogLevel.Info) == 0) return;

_handleLog.Invoke(logMessage.ToStringAndClear());
_handleLog?.Invoke(logMessage.ToStringAndClear());
}

public void LogWarning(string logMessage)
Expand Down
10 changes: 0 additions & 10 deletions TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = vodDownloadPage.imgThumbnail.Source
}
};
downloadTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -187,7 +186,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = vodDownloadPage.imgThumbnail.Source
}
};
chatTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -261,7 +259,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = clipDownloadPage.imgThumbnail.Source
}
};
downloadTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -294,7 +291,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = clipDownloadPage.imgThumbnail.Source
}
};
chatTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -359,7 +355,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = chatDownloadPage.imgThumbnail.Source
}
};
chatTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -419,7 +414,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = chatUpdatePage.imgThumbnail.Source
}
};
chatTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -459,7 +453,6 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
{
renderTask.Info.Thumbnail = image;
}
renderTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -520,7 +513,6 @@ private void EnqueueDataList()
Thumbnail = taskData.Thumbnail
}
};
downloadTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -553,7 +545,6 @@ private void EnqueueDataList()
Thumbnail = taskData.Thumbnail
}
};
downloadTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down Expand Up @@ -594,7 +585,6 @@ private void EnqueueDataList()
Thumbnail = taskData.Thumbnail
}
};
downloadTask.ChangeStatus(TwitchTaskStatus.Ready);

lock (PageQueue.taskLock)
{
Expand Down
Loading