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

View File

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