From be8c6b50ba98347d2d768d56dcdd776afd62306c Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 27 Jun 2023 23:37:13 +0200 Subject: [PATCH] Notification moved to TrangaTask --- Tranga/TrangaTask.cs | 16 ++++++++++++++++ Tranga/TrangaTasks/DownloadChapterTask.cs | 3 --- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index f4c3b24..faf5fb4 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -79,6 +79,22 @@ public abstract class TrangaTask while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running)) 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()) taskManager.DeleteTask(childTask); diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index 4fd4ef8..008026d 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -27,9 +27,6 @@ public class DownloadChapterTask : TrangaTask Connector connector = taskManager.GetConnector(this.connectorName); connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings); 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; }