From c813e1854d08a9c331fbc1eda9abe14e6f6088ce Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 1 Sep 2023 22:39:22 +0200 Subject: [PATCH] Do not add duplicate jobs --- Tranga/Jobs/JobBoss.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 8ae2a06..7d40268 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -15,8 +15,28 @@ public class JobBoss : GlobalBase public void AddJob(Job job) { - Log($"Added {job}"); - this.jobs.Add(job); + if (ContainsJobLike(job)) + { + Log($"Already Contains Job {job}"); + } + else + { + Log($"Added {job}"); + this.jobs.Add(job); + } + } + + public bool ContainsJobLike(Job job) + { + if (job is DownloadChapter dcJob) + { + return this.GetJobsLike(dcJob.mangaConnector, chapter: dcJob.chapter).Any(); + }else if (job is DownloadNewChapters ncJob) + { + return this.GetJobsLike(ncJob.mangaConnector, ncJob.manga).Any(); + } + + return false; } public void RemoveJob(Job job)