fix(settings): archive rows keep offline sizes, edit no stray archive and keep edits made while a folder opens

- While the open archive's archive.json cannot be read, the rows show the index's templates and proxy size and the
  thumbnail size stays this PC's: the stand-in 320 no longer replaces the default of new archives. Settings ›
  Archive loads through RefreshSettingsAsync, so opening it also brings the index up to a change made elsewhere.
- With no archive folder the rows edit only this PC's defaults, never the first archive of the index.
- An Archive row edited (or Reset section) while the archive at a just-chosen folder is opening waits for it and
  goes to that archive (or stays a default when the folder holds none), instead of being undone when it opens.
- A portable copy whose data had to leave its OneDrive folder says so at start, with Open on the data folder.
- Opening Settings re-reads Start with Windows, which Task Manager may have changed meanwhile.

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 16:02:43 +00:00
1 parent 815782a708
commit d2e547f9d2
4 files changed
+127 -31

No files matched your search

+1
View File
@@ -8,6 +8,7 @@
<data name="Settings.Advanced.BackupDone" xml:space="preserve"><value>Index backed up</value></data> <data name="Settings.Advanced.BackupDone" xml:space="preserve"><value>Index backed up</value></data>
<data name="Settings.Advanced.BackupNow" xml:space="preserve"><value>Back up now</value></data> <data name="Settings.Advanced.BackupNow" xml:space="preserve"><value>Back up now</value></data>
<data name="Settings.Advanced.DataFolder" xml:space="preserve"><value>Data folder</value></data> <data name="Settings.Advanced.DataFolder" xml:space="preserve"><value>Data folder</value></data>
<data name="Settings.Advanced.DataOutsideOneDrive" xml:space="preserve"><value>Data kept outside OneDrive</value><comment>long</comment></data>
<data name="Settings.Advanced.Diagnostics" xml:space="preserve"><value>Diagnostics</value></data> <data name="Settings.Advanced.Diagnostics" xml:space="preserve"><value>Diagnostics</value></data>
<data name="Settings.Advanced.DiagnosticsDone" xml:space="preserve"><value>Diagnostics bundle saved</value></data> <data name="Settings.Advanced.DiagnosticsDone" xml:space="preserve"><value>Diagnostics bundle saved</value></data>
<data name="Settings.Advanced.DiagnosticsTitle" xml:space="preserve"><value>Save the diagnostics bundle to</value></data> <data name="Settings.Advanced.DiagnosticsTitle" xml:space="preserve"><value>Save the diagnostics bundle to</value></data>
+1
View File
@@ -8,6 +8,7 @@
<data name="Settings.Advanced.BackupDone" xml:space="preserve"><value>Copia dell'indice salvata</value></data> <data name="Settings.Advanced.BackupDone" xml:space="preserve"><value>Copia dell'indice salvata</value></data>
<data name="Settings.Advanced.BackupNow" xml:space="preserve"><value>Salva una copia</value></data> <data name="Settings.Advanced.BackupNow" xml:space="preserve"><value>Salva una copia</value></data>
<data name="Settings.Advanced.DataFolder" xml:space="preserve"><value>Cartella dati</value></data> <data name="Settings.Advanced.DataFolder" xml:space="preserve"><value>Cartella dati</value></data>
<data name="Settings.Advanced.DataOutsideOneDrive" xml:space="preserve"><value>Dati tenuti fuori da OneDrive</value></data>
<data name="Settings.Advanced.Diagnostics" xml:space="preserve"><value>Diagnostica</value></data> <data name="Settings.Advanced.Diagnostics" xml:space="preserve"><value>Diagnostica</value></data>
<data name="Settings.Advanced.DiagnosticsDone" xml:space="preserve"><value>Pacchetto diagnostico salvato</value></data> <data name="Settings.Advanced.DiagnosticsDone" xml:space="preserve"><value>Pacchetto diagnostico salvato</value></data>
<data name="Settings.Advanced.DiagnosticsTitle" xml:space="preserve"><value>Salva il pacchetto in</value></data> <data name="Settings.Advanced.DiagnosticsTitle" xml:space="preserve"><value>Salva il pacchetto in</value></data>
+80 -31
View File
@@ -45,6 +45,12 @@ public sealed class SettingsViewModel : SectionViewModel
private bool _isTesting; private bool _isTesting;
private CancellationTokenSource? _selfTest; private CancellationTokenSource? _selfTest;
private Archive? _archive; private Archive? _archive;
/// <summary>
/// The open of the archive at the folder chosen last (<see cref="RetargetArchiveAsync"/>), with the archive it found
/// there: edits of the Archive rows made meanwhile wait for it (<see cref="ArchiveAtFolderAsync"/>).
/// </summary>
private Task<Archive?> _retarget = Task.FromResult<Archive?>(null);
private bool _isDetectingFormats; private bool _isDetectingFormats;
private IReadOnlyList<BackupOption> _backups = []; private IReadOnlyList<BackupOption> _backups = [];
private BackupOption? _selectedBackup; private BackupOption? _selectedBackup;
@@ -82,7 +88,7 @@ public sealed class SettingsViewModel : SectionViewModel
_s.LastArchivePath = v.Length == 0 ? null : Path.GetFullPath(v); _s.LastArchivePath = v.Length == 0 ? null : Path.GetFullPath(v);
Save(); Save();
UpdateArchiveFree(); UpdateArchiveFree();
_ = RetargetArchiveAsync(); _retarget = RetargetArchiveAsync();
}, () => Loc.L("Tooltips.Settings.ArchiveRoot")); }, () => Loc.L("Tooltips.Settings.ArchiveRoot"));
FolderTemplate = new EditableField(_s.FolderTemplate, v => NamingPreview.Validate(v, isFolder: true), v => FolderTemplate = new EditableField(_s.FolderTemplate, v => NamingPreview.Validate(v, isFolder: true), v =>
{ {
@@ -770,7 +776,8 @@ public sealed class SettingsViewModel : SectionViewModel
/// <summary> /// <summary>
/// Loads what needs the services (certificates, cache usage, the open archive's settings), follows the server session, /// Loads what needs the services (certificates, cache usage, the open archive's settings), follows the server session,
/// applies "Background priority" while Titano is in front and says how a restore staged before this start went. /// applies "Background priority" while Titano is in front and says how a restore staged before this start went, and
/// where the data of a portable copy in a OneDrive folder went.
/// </summary> /// </summary>
public void Attach() public void Attach()
{ {
@@ -798,6 +805,10 @@ public sealed class SettingsViewModel : SectionViewModel
Shell.Notify(Loc.L("Settings.Advanced.RestoreFailed"), Loc.L("Errors.Backup.Deferred"), isError: true); Shell.Notify(Loc.L("Settings.Advanced.RestoreFailed"), Loc.L("Errors.Backup.Deferred"), isError: true);
break; break;
} }
// BRIEF §6.2: a portable copy in a folder OneDrive synchronises keeps its data in this user's folder instead.
if (Shell.Services.Environment.SyncedFolder is not null)
Shell.Notify(Loc.L("Settings.Advanced.DataOutsideOneDrive"), Formatting.LeftToRight(DataFolder), Loc.L("Common.Open"),
Loc.L("Tooltips.Settings.OpenDataFolder"), () => ShellActions.Reveal(DataFolder));
Startup.Refresh(); Startup.Refresh();
} }
@@ -868,33 +879,39 @@ public sealed class SettingsViewModel : SectionViewModel
/// <summary> /// <summary>
/// Takes the archive and server values other screens set (opening an archive, connecting), unless the field holds an /// Takes the archive and server values other screens set (opening an archive, connecting), unless the field holds an
/// edit not committed yet. /// edit not committed yet, and the sign-in entry as Task Manager may have left it.
/// </summary> /// </summary>
private void ReloadShared() private void ReloadShared()
{ {
if (!ArchiveRoot.IsDirty) ArchiveRoot.Load(_s.LastArchivePath ?? string.Empty); if (!ArchiveRoot.IsDirty) ArchiveRoot.Load(_s.LastArchivePath ?? string.Empty);
if (!DefaultServer.IsDirty) DefaultServer.Load(ServerAddress.Display(_s.ServerUrl)); if (!DefaultServer.IsDirty) DefaultServer.Load(ServerAddress.Display(_s.ServerUrl));
OnPropertyChanged(nameof(StartWithWindows));
UpdateArchiveFree(); UpdateArchiveFree();
_ = LoadArchiveAsync(); _ = LoadArchiveAsync();
if (_page == SettingsPage.Advanced) LoadBackups(); if (_page == SettingsPage.Advanced) LoadBackups();
} }
/// <summary> /// <summary>
/// Shows the open archive's own templates, proxy size and thumbnail size (its archive.json; the index's while it is /// Shows the open archive's own templates, proxy size and thumbnail size unless a field holds an edit; they also become
/// offline) unless a field holds an edit; they also become the defaults of new archives. The open archive is the one /// the defaults of new archives. They come from its archive.json, which also brings the index up to a change another
/// at the archive folder of this PC, never another one of the index: with none registered there, the rows edit only /// process sharing the archive made, so imports follow it too. While the file cannot be read (offline), the templates
/// this PC's defaults. /// and proxy size are the index's and the thumbnail size stays this PC's: only the file knows the archive's. The open
/// archive is the one at the archive folder of this PC, never another one of the index: with no folder, or none
/// registered there, the rows edit only this PC's defaults. Returns that archive (null for none).
/// </summary> /// </summary>
private async Task LoadArchiveAsync() private async Task<Archive?> LoadArchiveAsync()
{ {
if (Shell.Services.Database is not { } db || Shell.Services.Archives is not { } archives) return; if (Shell.Services.Database is not { } db || Shell.Services.Archives is not { } archives) return null;
Archive? archive = null;
try try
{ {
var registered = await db.Archives.ListAsync(); var registered = await db.Archives.ListAsync();
var archive = _s.LastArchivePath is { Length: > 0 } root ? CurrentArchive.At(registered, root) : CurrentArchive.Pick(registered, null); archive = _s.LastArchivePath is { Length: > 0 } root ? CurrentArchive.At(registered, root) : null;
_archive = archive; _archive = archive;
if (archive is null) return; if (archive is null) return null;
var settings = await Task.Run(() => archives.GetSettingsAsync(archive.Id)); var settings = await Task.Run(() => archives.RefreshSettingsAsync(archive.Id))
?? new ArchiveSettings(archive.Name, new LayoutTemplates { Folder = archive.FolderTemplate, File = archive.FileTemplate },
new ProxyPolicy { LongEdge = archive.ProxyLongEdge }, new ThumbnailPolicy { LongEdge = _s.ThumbnailLongEdge });
if (!FolderTemplate.IsDirty) FolderTemplate.Load(settings.Templates.Folder); if (!FolderTemplate.IsDirty) FolderTemplate.Load(settings.Templates.Folder);
if (!FileTemplate.IsDirty) FileTemplate.Load(settings.Templates.File); if (!FileTemplate.IsDirty) FileTemplate.Load(settings.Templates.File);
var changed = _s.FolderTemplate != settings.Templates.Folder || _s.FileTemplate != settings.Templates.File var changed = _s.FolderTemplate != settings.Templates.Folder || _s.FileTemplate != settings.Templates.File
@@ -915,20 +932,41 @@ public sealed class SettingsViewModel : SectionViewModel
{ {
Log.Warning("settings", "The open archive's settings could not be read", ex); Log.Warning("settings", "The open archive's settings could not be read", ex);
} }
return archive;
}
/// <summary>
/// The archive an Archive row edits, as the folder was when the row was edited (<paramref name="retarget"/>, the
/// latest folder change then): the open one, or, while the archive at that folder is still opening, the one found
/// there once it has (null for none), so the edit is neither lost nor sent to a folder chosen later.
/// </summary>
private async Task<Archive?> ArchiveAtFolderAsync(Task<Archive?> retarget)
{
if (retarget.IsCompleted) return _archive;
// Its failures were told already; only the archive it found matters here.
await ((Task)retarget).ConfigureAwait(ConfigureAwaitOptions.ContinueOnCapturedContext | ConfigureAwaitOptions.SuppressThrowing);
return retarget.IsCompletedSuccessfully ? retarget.Result : null;
} }
/// <summary> /// <summary>
/// Writes one Archive row into the open archive's archive.json and index through the archive engine (BRIEF §7). When /// Writes one Archive row into the open archive's archive.json and index through the archive engine (BRIEF §7). When
/// that fails (offline, read-only, busy) the user hears why and the rows show the archive's values again. /// that fails (offline, read-only, busy) the user hears why and the rows show the archive's values again. An edit made
/// while the archive at a folder just chosen is opening waits for it, then goes to that archive (or stays this PC's
/// default when there is none), instead of being lost.
/// </summary> /// </summary>
private async Task UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit) private async Task UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit)
{ {
if (_archive is not { } archive || Shell.Services.Archives is not { } archives) return; var retarget = _retarget;
var waited = !retarget.IsCompleted;
if (await ArchiveAtFolderAsync(retarget) is not { } archive || Shell.Services.Archives is not { } archives) return;
try try
{ {
var updated = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit)); var updated = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
// The archive folder may have changed meanwhile: the rows then belong to another archive. // The archive folder may have changed meanwhile: the rows then belong to another archive.
if (_archive?.Id == updated.Id) _archive = updated; if (_archive?.Id == updated.Id) _archive = updated;
// The open showed the archive's values over the edit: unless another folder was chosen since, the rows (and
// this PC's defaults) take what it holds now.
if (waited && _retarget == retarget) await LoadArchiveAsync();
} }
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or InvalidDataException or NewerFormatException catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or InvalidDataException or NewerFormatException
or DatabaseException) or DatabaseException)
@@ -950,9 +988,9 @@ public sealed class SettingsViewModel : SectionViewModel
/// <summary> /// <summary>
/// The archive folder changed: an archive already there is registered as at start (relinked when it moved) and given /// The archive folder changed: an archive already there is registered as at start (relinked when it moved) and given
/// its rescan, and the rows show its settings; any other folder leaves them with this PC's defaults for new archives. /// its rescan, and the rows show its settings; any other folder leaves them with this PC's defaults for new archives.
/// Later edits never reach the archive shown before. /// Later edits never reach the archive shown before. Returns the archive found there (null for none).
/// </summary> /// </summary>
private async Task RetargetArchiveAsync() private async Task<Archive?> RetargetArchiveAsync()
{ {
_archive = null; _archive = null;
if (_s.LastArchivePath is { } root && Shell.Services.Archives is { } archives) if (_s.LastArchivePath is { } root && Shell.Services.Archives is { } archives)
@@ -968,7 +1006,7 @@ public sealed class SettingsViewModel : SectionViewModel
Shell.Notify(Loc.L("Errors.Archive.Open"), ArchiveActions.Cause(ex), isError: true); Shell.Notify(Loc.L("Errors.Archive.Open"), ArchiveActions.Cause(ex), isError: true);
} }
} }
await LoadArchiveAsync(); return await LoadArchiveAsync();
} }
/// <summary> /// <summary>
@@ -1306,19 +1344,8 @@ public sealed class SettingsViewModel : SectionViewModel
UiLanguage.Apply(null); UiLanguage.Apply(null);
break; break;
case SettingsPage.Archive: case SettingsPage.Archive:
// The rows are the open archive's own: resetting them changes it for everyone sharing it, so only when confirmed. _ = ResetArchiveAsync(defaults);
var open = _archive; return;
if (open is not null && !ConfirmArchiveReset(open)) return;
_s.FolderTemplate = defaults.FolderTemplate;
_s.FileTemplate = defaults.FileTemplate;
_s.ProxyLongEdge = defaults.ProxyLongEdge;
_s.ThumbnailLongEdge = defaults.ThumbnailLongEdge;
_s.ScanIntervalMinutes = defaults.ScanIntervalMinutes;
FolderTemplate.Load(_s.FolderTemplate);
FileTemplate.Load(_s.FileTemplate);
UpdatePreview();
if (open is not null) _ = PushArchiveSettingsAsync();
break;
case SettingsPage.Import: case SettingsPage.Import:
_s.ImportSessionGapMinutes = defaults.ImportSessionGapMinutes; _s.ImportSessionGapMinutes = defaults.ImportSessionGapMinutes;
_s.ImportMinimumFrames = defaults.ImportMinimumFrames; _s.ImportMinimumFrames = defaults.ImportMinimumFrames;
@@ -1367,6 +1394,28 @@ public sealed class SettingsViewModel : SectionViewModel
Shell.Server.Refresh(); Shell.Server.Refresh();
} }
/// <summary>
/// Archive › Reset section. The rows are the open archive's own: resetting them changes it for everyone sharing it, so
/// only when confirmed. The archive at a folder just chosen is opened first, so the question names it and the reset
/// reaches it instead of being undone when it opens.
/// </summary>
private async Task ResetArchiveAsync(AppSettings defaults)
{
var open = await ArchiveAtFolderAsync(_retarget);
if (open is not null && !ConfirmArchiveReset(open)) return;
_s.FolderTemplate = defaults.FolderTemplate;
_s.FileTemplate = defaults.FileTemplate;
_s.ProxyLongEdge = defaults.ProxyLongEdge;
_s.ThumbnailLongEdge = defaults.ThumbnailLongEdge;
_s.ScanIntervalMinutes = defaults.ScanIntervalMinutes;
FolderTemplate.Load(_s.FolderTemplate);
FileTemplate.Load(_s.FileTemplate);
UpdatePreview();
Save();
OnAllPropertiesChanged();
if (open is not null) await PushArchiveSettingsAsync();
}
private void LoadImportFields() private void LoadImportFields()
{ {
SessionGap.Load(_s.ImportSessionGapMinutes.ToString(CultureInfo.CurrentCulture)); SessionGap.Load(_s.ImportSessionGapMinutes.ToString(CultureInfo.CurrentCulture));
@@ -1484,7 +1533,7 @@ public sealed class SettingsViewModel : SectionViewModel
ApplyAll(imported); ApplyAll(imported);
// Settings of a PC never rewrite the shared archive.json: the imported templates and sizes are the defaults of new // Settings of a PC never rewrite the shared archive.json: the imported templates and sizes are the defaults of new
// archives, and the rows show the own settings of the archive at the (possibly imported) archive folder. // archives, and the rows show the own settings of the archive at the (possibly imported) archive folder.
_ = RetargetArchiveAsync(); _retarget = RetargetArchiveAsync();
Shell.Notify(Loc.L("Settings.Import.Done")); Shell.Notify(Loc.L("Settings.Import.Done"));
} }
@@ -169,6 +169,51 @@ public sealed class SettingsScreenSmokeTests
installs[0].Command.Execute(null); installs[0].Command.Execute(null);
}); });
[Test]
public Task ArchiveRowsEditOnlyTheArchiveAtTheFolderAndKeepEditsMadeWhileItOpens() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
var settings = shell.Settings;
var db = shell.Services.Database!;
var archive = Assert.NotNull(await Titano.App.Archiving.CurrentArchive.FindAsync(db, null));
var manifestPath = new Titano.Core.Archiving.ArchivePaths(archive.RootPath).ManifestPath;
static Titano.Core.Archiving.ArchiveManifest Read(string path) => Titano.Core.Archiving.ManifestStore.ReadArchive(path);
shell.Navigate(SectionKey.Settings);
settings.Page = SettingsPage.Archive;
// No archive folder: a template edit is this PC's default only, never the first archive of the index.
settings.ArchiveRoot.Text = string.Empty;
Assert.True(settings.ArchiveRoot.Commit());
settings.FolderTemplate.Text = "{camera}/{date}";
Assert.True(settings.FolderTemplate.Commit());
// The archive's folder is chosen and a template edited at once, while that archive is still opening: the edit
// reaches its archive.json instead of being undone when it opens, and the row shows it.
settings.ArchiveRoot.Text = archive.RootPath;
Assert.True(settings.ArchiveRoot.Commit());
settings.FileTemplate.Text = "{date}_{n:0000}";
Assert.True(settings.FileTemplate.Commit());
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}_{n:0000}", "the edit reached the archive that was opening");
await WaitAsync(() => settings.FileTemplate.Text == "{date}_{n:0000}" && shell.Services.Settings.FileTemplate == "{date}_{n:0000}", "the row shows it");
Assert.NotEqual("{camera}/{date}", Read(manifestPath).LayoutTemplates.Folder);
// Offline, only archive.json knows the thumbnail size: this PC's stays instead of becoming the default.
Titano.Core.Archiving.ManifestStore.WriteArchive(manifestPath, Read(manifestPath) with { ThumbnailPolicy = new Titano.Core.Archiving.ThumbnailPolicy { LongEdge = 480 } });
shell.Navigate(SectionKey.Library);
shell.Navigate(SectionKey.Settings);
await WaitAsync(() => shell.Services.Settings.ThumbnailLongEdge == 480, "the archive's thumbnail size is shown");
var row = Assert.NotNull(await db.Archives.GetAsync(archive.Id));
await db.Archives.UpsertAsync(row with { ProxyLongEdge = 2560 });
System.IO.File.Move(manifestPath, manifestPath + ".away");
shell.Navigate(SectionKey.Library);
shell.Navigate(SectionKey.Settings);
await WaitAsync(() => shell.Services.Settings.ProxyLongEdge == 2560, "the index's proxy size is shown while offline");
Assert.Equal(480, shell.Services.Settings.ThumbnailLongEdge);
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
});
[Test] [Test]
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () => public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
{ {