fix(app): archive picks, early import job ends and language switches

- Archive: picking another archive while the screen was reading kept the old
  archive's tree and figures while Scan, Verify and the set actions targeted the
  new one, and reloads asked for during a read were dropped. A load requested
  during a read now runs once more after it, a read whose archive is no longer
  picked shows nothing, and a new pick clears the tree and the online state
  until the picked archive is read.
- Import: a job that ended before the screen recorded its id (a destination
  gone offline) left the screen copying forever; its state is read back once.
  A replaced import result is disposed, so it no longer stays alive through the
  language event with its whole plan.
- Library: the timeline's month readouts are made again on a language switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 10:13:53 +00:00
1 parent 579ffd446d
commit d47e3e9b49
6 files changed
+170 -7

No files matched your search

+47 -6
View File
@@ -52,6 +52,7 @@ public sealed class ArchiveViewModel : SectionViewModel
private int _viewIndex;
private bool _loaded;
private Task _load = Task.CompletedTask;
private bool _reloadPending;
private bool _jobEvents;
private string _lastScanText = string.Empty;
private ArchiveDialogViewModel? _dialog;
@@ -121,9 +122,19 @@ public sealed class ArchiveViewModel : SectionViewModel
set
{
if (value is null || value == _archive) return;
var other = value.Id != _archive?.Id;
_archive = value;
_duplicates = null;
_orphans = null;
if (other)
{
// Until the picked archive is read, nothing of the previous one stays actionable: no tree to take a set
// from, no availability to allow a scan.
_tree = null;
_availability = ArchiveAvailability.Offline;
RebuildRows();
CommandManager.InvalidateRequerySuggested();
}
_ = LoadAsync();
}
}
@@ -370,8 +381,30 @@ public sealed class ArchiveViewModel : SectionViewModel
_ = LoadAsync();
}
/// <summary>Reads archives, figures, tree, health and recent maintenance of the selected archive; joins a read in progress.</summary>
public Task LoadAsync() => _load.IsCompleted ? _load = ReadAsync() : _load;
/// <summary>
/// Reads archives, figures, tree, health and recent maintenance of the selected archive. A call during a read joins
/// it and reads once more when it ends, so a newly picked archive, a language switch or a finished job is never lost
/// behind the read in progress.
/// </summary>
public Task LoadAsync()
{
if (!_load.IsCompleted)
{
_reloadPending = true;
return _load;
}
return _load = ReadUntilCurrentAsync();
}
private async Task ReadUntilCurrentAsync()
{
do
{
_reloadPending = false;
await ReadAsync();
}
while (_reloadPending);
}
private async Task ReadAsync()
{
@@ -384,12 +417,16 @@ public sealed class ArchiveViewModel : SectionViewModel
_archive ??= CurrentArchive.Pick(Archives, Services.Settings.LastArchivePath);
if (_archive is not { } archive) return;
var root = archive.RootPath;
_availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root)));
_stats = await db.Sequences.GetStatsAsync(archive.Id);
var availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root)));
var stats = await db.Sequences.GetStatsAsync(archive.Id);
var sequences = await ListSequencesAsync(db, archive.Id);
var withoutProxies = await db.Sequences.CountAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = SequenceStatus.ProxiesBuilt });
ShowFigures(_stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, _availability, sequences));
// Another archive was picked meanwhile: the read its pick queued shows it, never this one's tree.
if (!IsShowing(archive)) return;
_availability = availability;
_stats = stats;
ShowFigures(stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, availability, sequences));
await LoadRecentAsync(db, archive);
}
catch (DatabaseException ex)
@@ -572,6 +609,7 @@ public sealed class ArchiveViewModel : SectionViewModel
var jobs = new List<Job>();
foreach (var kind in MaintenanceReports.MaintenanceKinds)
jobs.AddRange((await db.Jobs.ListAsync(null, kind, RecentCount)).Items.Where(j => j.TargetIds.Contains(archive.Id)));
if (!IsShowing(archive)) return;
Recent = MaintenanceReports.Recent(jobs, RecentCount);
var scan = jobs.Where(j => j.Kind == JobKind.Scan && j is { State: JobState.Done, Finished: not null, Started: not null })
.MaxBy(j => j.Finished);
@@ -613,6 +651,9 @@ public sealed class ArchiveViewModel : SectionViewModel
private bool IsOnline() => _archive is not null && _availability == ArchiveAvailability.Online;
/// <summary>The archive a read started with is still the one picked.</summary>
private bool IsShowing(Core.Model.Archive archive) => _archive?.Id == archive.Id;
/// <summary>A command's tooltip, or why it is disabled: these commands write to the archive or read all of it.</summary>
private string WhenOnline(string key) => _archive is null || IsOnline() ? Loc.L(key) : Loc.L("Archive.Blocked.NotOnline");