fix(app): an import keeps its result and resume when its card leaves and returns

Re-listing the devices no longer re-plans the card of a running, failed or
finished import, so a removed card can resume its job after re-insertion and
the verification result stays after ejecting. The source list and profile
edits are locked while an import runs.

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-02 22:30:13 +00:00
1 parent cb41fb69ee
commit d4f7396ac2
3 files changed
+16 -16

No files matched your search

+1 -1
View File
@@ -97,7 +97,7 @@
VerticalContentAlignment="Top"> VerticalContentAlignment="Top">
<TextBlock Text="{l:Loc Import.Devices.Auto}" TextWrapping="Wrap" Foreground="{DynamicResource Brush.TextMuted}" /> <TextBlock Text="{l:Loc Import.Devices.Auto}" TextWrapping="Wrap" Foreground="{DynamicResource Brush.TextMuted}" />
</CheckBox> </CheckBox>
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False"> <ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False" IsEnabled="{Binding IsFormEnabled}">
<StackPanel> <StackPanel>
<ListBox ItemsSource="{Binding Sources}" SelectedItem="{Binding SelectedSource}" ItemContainerStyle="{StaticResource ListBoxItem.Device}" <ListBox ItemsSource="{Binding Sources}" SelectedItem="{Binding SelectedSource}" ItemContainerStyle="{StaticResource ListBoxItem.Device}"
AutomationProperties.Name="{l:Loc Import.Devices.Title}"> AutomationProperties.Name="{l:Loc Import.Devices.Title}">
+13 -12
View File
@@ -113,8 +113,8 @@ public sealed class ImportViewModel : SectionViewModel
field.Text += token.Text; field.Text += token.Text;
field.Commit(); field.Commit();
}); });
RenameCommand = new RelayCommand(() => IsRenaming = true, () => _selected?.Card is not null); RenameCommand = new RelayCommand(() => IsRenaming = true, () => CanEditProfile);
ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => _selected?.Card is not null); ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => CanEditProfile);
ShowPlanCommand = new RelayCommand(() => Details = _plan is null ? null : ImportPlans.Details(_plan, _choices.Destination, _choices.VerifyCopies), ShowPlanCommand = new RelayCommand(() => Details = _plan is null ? null : ImportPlans.Details(_plan, _choices.Destination, _choices.VerifyCopies),
() => _plan is not null); () => _plan is not null);
CloseDetailsCommand = new RelayCommand(() => Details = null); CloseDetailsCommand = new RelayCommand(() => Details = null);
@@ -128,7 +128,7 @@ public sealed class ImportViewModel : SectionViewModel
RetryCommand = new AsyncRelayCommand(RetryAsync, () => _phase == ImportPhase.Failed); RetryCommand = new AsyncRelayCommand(RetryAsync, () => _phase == ImportPhase.Failed);
shell.Services.Devices.Arrived += device => Dispatch(() => _ = CardInsertedAsync(device)); shell.Services.Devices.Arrived += device => Dispatch(() => _ = CardInsertedAsync(device));
shell.Services.Devices.Removed += device => Dispatch(() => _ = OnRemovedAsync(device)); shell.Services.Devices.Removed += removed => Dispatch(() => _ = OnRemovedAsync());
shell.Services.Server.PropertyChanged += (_, _) => Dispatch(() => OnPropertyChanged(string.Empty)); shell.Services.Server.PropertyChanged += (_, _) => Dispatch(() => OnPropertyChanged(string.Empty));
} }
@@ -193,7 +193,8 @@ public sealed class ImportViewModel : SectionViewModel
public EditableField Nickname { get; } public EditableField Nickname { get; }
public bool CanEditProfile => _selected?.Card is not null; /// <summary>A remembered card's profile can be edited, except while its import runs.</summary>
public bool CanEditProfile => _selected?.Card is not null && _phase != ImportPhase.Running;
public IReadOnlyList<ProfileSource> OtherCards => public IReadOnlyList<ProfileSource> OtherCards =>
[ [
@@ -479,14 +480,18 @@ public sealed class ImportViewModel : SectionViewModel
var key = _selected?.Key; var key = _selected?.Key;
var pool = Rebuild(); var pool = Rebuild();
var again = pool.FirstOrDefault(s => s.Key == key) ?? pool.FirstOrDefault(s => s.IsInserted && s.Kind == SourceKind.Card); var again = pool.FirstOrDefault(s => s.Key == key) ?? pool.FirstOrDefault(s => s.IsInserted && s.Kind == SourceKind.Card);
if (!Equals(again, _selected)) // The card of a running, failed or finished import may leave and come back: its import, result and resume stay.
var keepsImport = again is not null && again.Key == key && _phase is ImportPhase.Running or ImportPhase.Failed or ImportPhase.Done;
if (Equals(again, _selected) || keepsImport)
{ {
_selected = again; _selected = again;
OnSourceChanged(); _result?.SetDevice(again?.Device);
OnPropertyChanged(string.Empty);
} }
else else
{ {
OnPropertyChanged(string.Empty); _selected = again;
OnSourceChanged();
} }
} }
@@ -1058,11 +1063,7 @@ public sealed class ImportViewModel : SectionViewModel
if (_phase == ImportPhase.Running && _jobSourceKey == identity) await CancelAsync(); if (_phase == ImportPhase.Running && _jobSourceKey == identity) await CancelAsync();
} }
private async Task OnRemovedAsync(CardDevice device) private Task OnRemovedAsync() => RefreshSourcesAsync();
{
await RefreshSourcesAsync();
_result?.SetDevice(Services.Devices.Devices.FirstOrDefault(d => d.Identity == _selected?.Device?.Identity));
}
private static void Dispatch(Action action) private static void Dispatch(Action action)
{ {
@@ -94,9 +94,8 @@ public sealed class ImportFlowTests(TestContext context)
Assert.True(outcome.IsComplete); Assert.True(outcome.IsComplete);
Assert.True(outcome.Verified); Assert.True(outcome.Verified);
Assert.NotEmpty(reports); Assert.NotEmpty(reports);
foreach (var s in plan.Sessions) foreach (var (folder, name) in plan.Sessions.SelectMany(s => s.Items.Select(i => (s.Folder, i.FileName))))
foreach (var item in s.Items) Assert.FileExists(Path.Combine(target, folder, name));
Assert.FileExists(Path.Combine(target, s.Folder, item.FileName));
var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation), var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation),
new FolderImportSink(target), verify: true, null, context.Cancellation); new FolderImportSink(target), verify: true, null, context.Cancellation);