2
0

Notification moved to TrangaTask

This commit is contained in:
glax 2023-06-27 23:37:13 +02:00
parent a38fcf50ca
commit be8c6b50ba
2 changed files with 16 additions and 3 deletions

View File

@ -79,6 +79,22 @@ public abstract class TrangaTask
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running)) while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
Thread.Sleep(1000); Thread.Sleep(1000);
if((int)statusCode >= 200 && (int)statusCode < 300 && parentTask is null)
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
switch (this.task)
{
case Task.MonitorPublication:
MonitorPublicationTask mpt = (MonitorPublicationTask)this;
nm.SendNotification("Downloaded new chapters",
$"{mpt.publication.sortName}: {this.childTasks.Count(ct => ct.state is ExecutionState.Success)} new chapters.");
break;
case Task.DownloadChapter:
DownloadChapterTask dct = (DownloadChapterTask)this;
nm.SendNotification("Chapter downloaded", $"{dct.publication.sortName} {dct.chapter.chapterNumber} {dct.chapter.name}");
break;
}
foreach(TrangaTask childTask in this.childTasks.ToArray()) foreach(TrangaTask childTask in this.childTasks.ToArray())
taskManager.DeleteTask(childTask); taskManager.DeleteTask(childTask);

View File

@ -27,9 +27,6 @@ public class DownloadChapterTask : TrangaTask
Connector connector = taskManager.GetConnector(this.connectorName); Connector connector = taskManager.GetConnector(this.connectorName);
connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings); connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings);
HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken); HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
if((int)downloadSuccess >= 200 && (int)downloadSuccess < 300 && parentTask is not null)
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
nm.SendNotification("New Chapter downloaded", $"{this.publication.sortName} {this.chapter.chapterNumber} {this.chapter.name}");
return downloadSuccess; return downloadSuccess;
} }