diff --git a/src/Titano.App/Sections/ImportView.xaml b/src/Titano.App/Sections/ImportView.xaml
index a014265b..064a7f44 100644
--- a/src/Titano.App/Sections/ImportView.xaml
+++ b/src/Titano.App/Sections/ImportView.xaml
@@ -97,7 +97,7 @@
VerticalContentAlignment="Top">
-
+
diff --git a/src/Titano.App/Sections/ImportViewModel.cs b/src/Titano.App/Sections/ImportViewModel.cs
index 471a453c..28855312 100644
--- a/src/Titano.App/Sections/ImportViewModel.cs
+++ b/src/Titano.App/Sections/ImportViewModel.cs
@@ -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;
+ /// A remembered card's profile can be edited, except while its import runs.
+ public bool CanEditProfile => _selected?.Card is not null && _phase != ImportPhase.Running;
public IReadOnlyList 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)
{
diff --git a/tests/Titano.App.Tests/Import/ImportFlowTests.cs b/tests/Titano.App.Tests/Import/ImportFlowTests.cs
index 4b8eef2a..1dd8fbec 100644
--- a/tests/Titano.App.Tests/Import/ImportFlowTests.cs
+++ b/tests/Titano.App.Tests/Import/ImportFlowTests.cs
@@ -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);