WhileDownloading also refresh after all downloads are finished

This commit is contained in:
2025-09-21 17:09:38 +02:00
parent 55a8b09310
commit 8e2f9ebbe5
2 changed files with 19 additions and 14 deletions

View File

@@ -146,25 +146,27 @@ public static class Tranga
private static Action DefaultAfterWork(BaseWorker worker, Action? callback = null) => () =>
{
Log.Debug($"DefaultAfterWork {worker}");
if (RunningWorkers.TryGetValue(worker, out Task<BaseWorker[]>? task))
try
{
Log.Debug($"Waiting for Children to exit {worker}");
task.Wait();
if (task.IsCompleted)
if (RunningWorkers.TryGetValue(worker, out Task<BaseWorker[]>? task))
{
try
Log.Debug($"Waiting for Children to exit {worker}");
task.Wait();
if (task.IsCompleted)
{
Log.Debug($"Children done {worker}");
BaseWorker[] newWorkers = task.Result;
Log.Debug($"{worker} created {newWorkers.Length} new Workers.");
AddWorkers(newWorkers);
}
catch (Exception e)
{
Log.Error(e);
}
}else Log.Warn($"Children failed: {worker}");
}else
Log.Warn($"Children failed: {worker}");
}
RunningWorkers.Remove(worker, out _);
}
catch (Exception e)
{
Log.Error(e);
}
RunningWorkers.Remove(worker, out _);
callback?.Invoke();
};

View File

@@ -139,18 +139,21 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
Log.Debug($"Downloaded chapter {chapter}.");
bool refreshLibrary = await CheckLibraryRefresh();
if(refreshLibrary)
Log.Info($"Condition {Tranga.Settings.LibraryRefreshSetting} met.");
return refreshLibrary? [new RefreshLibrariesWorker()] : [];
}
private async Task<bool> CheckLibraryRefresh() => Tranga.Settings.LibraryRefreshSetting switch
{
LibraryRefreshSetting.AfterAllFinished => (await StartNewChapterDownloadsWorker.GetMissingChapters(DbContext, CancellationToken)).Count == 0,
LibraryRefreshSetting.AfterAllFinished => await AllDownloadsFinished(),
LibraryRefreshSetting.AfterMangaFinished => await DbContext.MangaConnectorToChapter.Include(chId => chId.Obj).Where(chId => chId.UseForDownload).AllAsync(chId => chId.Obj.Downloaded, CancellationToken),
LibraryRefreshSetting.AfterEveryChapter => true,
LibraryRefreshSetting.WhileDownloading => DateTime.UtcNow.Subtract(RefreshLibrariesWorker.LastRefresh).TotalMinutes > Tranga.Settings.RefreshLibraryWhileDownloadingEveryMinutes,
LibraryRefreshSetting.WhileDownloading => await AllDownloadsFinished() || DateTime.UtcNow.Subtract(RefreshLibrariesWorker.LastRefresh).TotalMinutes > Tranga.Settings.RefreshLibraryWhileDownloadingEveryMinutes,
_ => true
};
private async Task<bool> AllDownloadsFinished() => (await StartNewChapterDownloadsWorker.GetMissingChapters(DbContext, CancellationToken)).Count == 0;
private void ProcessImage(string imagePath)
{