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:
4 files changed
+127
-31
No files matched your search
@@ -8,6 +8,7 @@
|
||||
<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.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.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>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<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.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.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>
|
||||
|
||||
@@ -45,6 +45,12 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
private bool _isTesting;
|
||||
private CancellationTokenSource? _selfTest;
|
||||
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 IReadOnlyList<BackupOption> _backups = [];
|
||||
private BackupOption? _selectedBackup;
|
||||
@@ -82,7 +88,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
_s.LastArchivePath = v.Length == 0 ? null : Path.GetFullPath(v);
|
||||
Save();
|
||||
UpdateArchiveFree();
|
||||
_ = RetargetArchiveAsync();
|
||||
_retarget = RetargetArchiveAsync();
|
||||
}, () => Loc.L("Tooltips.Settings.ArchiveRoot"));
|
||||
FolderTemplate = new EditableField(_s.FolderTemplate, v => NamingPreview.Validate(v, isFolder: true), v =>
|
||||
{
|
||||
@@ -770,7 +776,8 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
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);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -868,33 +879,39 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
private void ReloadShared()
|
||||
{
|
||||
if (!ArchiveRoot.IsDirty) ArchiveRoot.Load(_s.LastArchivePath ?? string.Empty);
|
||||
if (!DefaultServer.IsDirty) DefaultServer.Load(ServerAddress.Display(_s.ServerUrl));
|
||||
OnPropertyChanged(nameof(StartWithWindows));
|
||||
UpdateArchiveFree();
|
||||
_ = LoadArchiveAsync();
|
||||
if (_page == SettingsPage.Advanced) LoadBackups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the open archive's own templates, proxy size and thumbnail size (its archive.json; the index's while it is
|
||||
/// offline) unless a field holds an edit; they also become the defaults of new archives. The open archive is the one
|
||||
/// at the archive folder of this PC, never another one of the index: with none registered there, the rows edit only
|
||||
/// this PC's defaults.
|
||||
/// Shows the open archive's own templates, proxy size and thumbnail size unless a field holds an edit; they also become
|
||||
/// the defaults of new archives. They come from its archive.json, which also brings the index up to a change another
|
||||
/// process sharing the archive made, so imports follow it too. While the file cannot be read (offline), the templates
|
||||
/// 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>
|
||||
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
|
||||
{
|
||||
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;
|
||||
if (archive is null) return;
|
||||
var settings = await Task.Run(() => archives.GetSettingsAsync(archive.Id));
|
||||
if (archive is null) return null;
|
||||
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 (!FileTemplate.IsDirty) FileTemplate.Load(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);
|
||||
}
|
||||
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>
|
||||
/// 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>
|
||||
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
|
||||
{
|
||||
var updated = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
|
||||
// The archive folder may have changed meanwhile: the rows then belong to another archive.
|
||||
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
|
||||
or DatabaseException)
|
||||
@@ -950,9 +988,9 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// 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>
|
||||
private async Task RetargetArchiveAsync()
|
||||
private async Task<Archive?> RetargetArchiveAsync()
|
||||
{
|
||||
_archive = null;
|
||||
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);
|
||||
}
|
||||
}
|
||||
await LoadArchiveAsync();
|
||||
return await LoadArchiveAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1306,19 +1344,8 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
UiLanguage.Apply(null);
|
||||
break;
|
||||
case SettingsPage.Archive:
|
||||
// The rows are the open archive's own: resetting them changes it for everyone sharing it, so only when confirmed.
|
||||
var open = _archive;
|
||||
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;
|
||||
_ = ResetArchiveAsync(defaults);
|
||||
return;
|
||||
case SettingsPage.Import:
|
||||
_s.ImportSessionGapMinutes = defaults.ImportSessionGapMinutes;
|
||||
_s.ImportMinimumFrames = defaults.ImportMinimumFrames;
|
||||
@@ -1367,6 +1394,28 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
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()
|
||||
{
|
||||
SessionGap.Load(_s.ImportSessionGapMinutes.ToString(CultureInfo.CurrentCulture));
|
||||
@@ -1484,7 +1533,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
ApplyAll(imported);
|
||||
// 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.
|
||||
_ = RetargetArchiveAsync();
|
||||
_retarget = RetargetArchiveAsync();
|
||||
Shell.Notify(Loc.L("Settings.Import.Done"));
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,51 @@ public sealed class SettingsScreenSmokeTests
|
||||
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]
|
||||
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user