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:
3 files changed
+16
-16
No files matched your search
@@ -97,7 +97,7 @@
|
||||
VerticalContentAlignment="Top">
|
||||
<TextBlock Text="{l:Loc Import.Devices.Auto}" TextWrapping="Wrap" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
</CheckBox>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False" IsEnabled="{Binding IsFormEnabled}">
|
||||
<StackPanel>
|
||||
<ListBox ItemsSource="{Binding Sources}" SelectedItem="{Binding SelectedSource}" ItemContainerStyle="{StaticResource ListBoxItem.Device}"
|
||||
AutomationProperties.Name="{l:Loc Import.Devices.Title}">
|
||||
|
||||
@@ -113,8 +113,8 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
field.Text += token.Text;
|
||||
field.Commit();
|
||||
});
|
||||
RenameCommand = new RelayCommand(() => IsRenaming = true, () => _selected?.Card is not null);
|
||||
ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => _selected?.Card is not null);
|
||||
RenameCommand = new RelayCommand(() => IsRenaming = true, () => CanEditProfile);
|
||||
ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => CanEditProfile);
|
||||
ShowPlanCommand = new RelayCommand(() => Details = _plan is null ? null : ImportPlans.Details(_plan, _choices.Destination, _choices.VerifyCopies),
|
||||
() => _plan is not null);
|
||||
CloseDetailsCommand = new RelayCommand(() => Details = null);
|
||||
@@ -128,7 +128,7 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
RetryCommand = new AsyncRelayCommand(RetryAsync, () => _phase == ImportPhase.Failed);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -193,7 +193,8 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
|
||||
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 =>
|
||||
[
|
||||
@@ -479,14 +480,18 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
var key = _selected?.Key;
|
||||
var pool = Rebuild();
|
||||
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;
|
||||
OnSourceChanged();
|
||||
_result?.SetDevice(again?.Device);
|
||||
OnPropertyChanged(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnPropertyChanged(string.Empty);
|
||||
_selected = again;
|
||||
OnSourceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1058,11 +1063,7 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
if (_phase == ImportPhase.Running && _jobSourceKey == identity) await CancelAsync();
|
||||
}
|
||||
|
||||
private async Task OnRemovedAsync(CardDevice device)
|
||||
{
|
||||
await RefreshSourcesAsync();
|
||||
_result?.SetDevice(Services.Devices.Devices.FirstOrDefault(d => d.Identity == _selected?.Device?.Identity));
|
||||
}
|
||||
private Task OnRemovedAsync() => RefreshSourcesAsync();
|
||||
|
||||
private static void Dispatch(Action action)
|
||||
{
|
||||
|
||||
@@ -94,9 +94,8 @@ public sealed class ImportFlowTests(TestContext context)
|
||||
Assert.True(outcome.IsComplete);
|
||||
Assert.True(outcome.Verified);
|
||||
Assert.NotEmpty(reports);
|
||||
foreach (var s in plan.Sessions)
|
||||
foreach (var item in s.Items)
|
||||
Assert.FileExists(Path.Combine(target, s.Folder, item.FileName));
|
||||
foreach (var (folder, name) in plan.Sessions.SelectMany(s => s.Items.Select(i => (s.Folder, i.FileName))))
|
||||
Assert.FileExists(Path.Combine(target, folder, name));
|
||||
|
||||
var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation),
|
||||
new FolderImportSink(target), verify: true, null, context.Cancellation);
|
||||
|
||||
Reference in new issue
Block a user