diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 8d67e04a..f6288036 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -432,7 +432,7 @@ The index has no file to copy Not available on this PC The index is on PostgreSQL, which its own tools back up - The archive makes no proxies (Settings › Archive › Proxies) + The archive makes no proxies (Settings › Archive › Proxy size) Queued by a schedule (Scheduled tab) Filter by target or kind as you type Open what this job worked on to see the problem @@ -625,8 +625,8 @@ Largest long edge frames are decoded at for deep analysis (half the native size up to this); wider is slower and sees finer detail Free space on the archive drive Root of the local archive; files are not moved · Enter applies, Esc reverts - Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled · a few seconds - Copies of the index made by the backup schedules and Back up now; choose the one to return to + Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled keep · a few seconds + Copies of the index made by the Index backup schedule (Jobs › Scheduled) or Back up now; choose the one to return to Choose the archive folder Choose the cache folder; a fast SSD helps Where frames spill and thumbnails are kept; a fast SSD helps · Enter applies, Esc reverts diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 232c9bde..35ab1709 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -423,7 +423,7 @@ Le attività che questa pianificazione ha messo in coda, dalla più recente Mostra questa attività nella coda con il suo log Rimuove le voci del registro di controllo più vecchie del limite - Riduce la cache a Impostazioni › Archiviazione › Limite cache, prima i file più vecchi + Riduce la cache a Impostazioni › Spazio su disco › Limite della cache, prima i file più vecchi Rimuove le attività concluse più vecchie del limite Elenca le voci del cestino più vecchie del limite; non elimina niente {0} è una pianificazione propria di questo PC: si può modificare, disattivare o ripristinare, non eliminare @@ -431,7 +431,7 @@ L'indice non ha un file da copiare Non disponibile su questo PC L'indice è su PostgreSQL, che si copia con i propri strumenti - L'archivio non crea proxy (Impostazioni › Archivio › Proxy) + L'archivio non crea proxy (Impostazioni › Archivio › Dimensione proxy) Messa in coda da una pianificazione (scheda Pianificate) Filtra per oggetto o tipo mentre scrivi Apre l'oggetto dell'attività per vedere il problema @@ -623,8 +623,8 @@ Lato lungo massimo dei fotogrammi decodificati per l'analisi profonda (metà della dimensione nativa fino a questo); più largo è più lento e vede dettagli più fini Spazio libero sull'unità dell'archivio Radice dell'archivio locale; i file non vengono spostati · Invio applica, Esc annulla - Copia l'indice nella cartella dei backup, che ne tiene quante le copie pianificate in Attività › Pianificate · pochi secondi - Copie dell'indice fatte dalle copie pianificate e da Salva una copia; scegli quella a cui tornare + Copia l'indice nella cartella dei backup, che ne conserva quante ne tengono le pianificazioni di copia in Attività › Pianificate · pochi secondi + Copie dell'indice fatte dalla pianificazione Copia dell'indice (Attività › Pianificate) o da Salva una copia; scegli quella a cui tornare Scegli la cartella dell'archivio Scegli la cartella della cache; un SSD veloce aiuta Dove vanno i fotogrammi temporanei e le miniature; un SSD veloce aiuta · Invio applica, Esc annulla diff --git a/src/Chronos.App/Infrastructure/AppServices.cs b/src/Chronos.App/Infrastructure/AppServices.cs index e2e25eec..fa2a549d 100644 --- a/src/Chronos.App/Infrastructure/AppServices.cs +++ b/src/Chronos.App/Infrastructure/AppServices.cs @@ -232,7 +232,8 @@ public sealed class AppServices : IAsyncDisposable /// /// Opens (or creates) the index at , migrates it (after a restore staged in Settings › /// Advanced replaced it, which needs no open index: it also recovers one that no longer opens), starts the job engine, - /// then in the background reopens the archive and starts the schedules (). + /// then in the background reopens the archive and starts the schedules (, false at once + /// when the index or the engine does not open). /// public async Task OpenAsync(string databasePath, CancellationToken ct = default) { @@ -246,11 +247,21 @@ public sealed class AppServices : IAsyncDisposable { OpenError = ex; Log.Error("app", "The index could not be opened", ex); + // No index, no schedules: Jobs › Scheduled says so instead of waiting for them. + _schedulerReady.TrySetResult(false); return; } - await StartJobsAsync(Database, startEngine: true, ct); - Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems); - Devices.Start(); + try + { + await StartJobsAsync(Database, startEngine: true, ct); + Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems); + Devices.Start(); + } + catch + { + _schedulerReady.TrySetResult(false); + throw; + } _schedules = RunSchedulesAsync(_stopping.Token); } diff --git a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs index 51964c5e..52054335 100644 --- a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs +++ b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs @@ -141,10 +141,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel { _owner = owner; _schedule = schedule; - var available = owner.Actions; - ActionOptions = [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info - ? new ScheduleActionOption(a, info.Available, info.Reason) - : new ScheduleActionOption(a, true, null))]; + ActionOptions = BuildActionOptions(); _action = schedule is not null ? ActionOptions.FirstOrDefault(o => o.Name == schedule.Action) ?? new ScheduleActionOption(schedule.Action, false, null) : ActionOptions.FirstOrDefault(o => o.IsAvailable) ?? ActionOptions[0]; @@ -154,7 +151,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel // When: the stored recurrence, or every day at 03:00 for a new schedule. var recurrence = ScheduleMapping.FromDto(schedule?.Recurrence) ?? ScheduleRecurrence.DailyAt(new TimeOnly(3, 0)); _kindIndex = (int)recurrence.Kind; - Units = [.. Enum.GetValues().Select(u => new SettingsOption(u, Loc.L("Jobs.Editor.Unit." + u)))]; + Units = BuildUnits(); _unit = Units.First(u => u.Value == (recurrence.Kind == RecurrenceKind.Every ? recurrence.Unit : RecurrenceUnit.Hours)); Every = new ScheduleField(Number(recurrence.Kind == RecurrenceKind.Every ? recurrence.Every : 6), ValidateEvery, () => Loc.L("Tooltips.Jobs.Editor.Every")); Time = new ScheduleField(recurrence.Time.ToString("HH:mm", CultureInfo.InvariantCulture), ValidateTime, () => Loc.L("Tooltips.Jobs.Editor.Time")); @@ -170,7 +167,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel Keep = new ScheduleField(string.Empty, v => ValidateNumber(v, 1, 100), () => Loc.L("Tooltips.Jobs.Editor.Keep")); LoadParameters(schedule?.Parameters ?? ScheduleActions.Defaults(_action.Name)); - Priorities = [.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption(p, ScheduleText.Priority(p)))]; + Priorities = BuildPriorities(); var priority = schedule is not null && JobWire.TryParsePriority(schedule.Priority, out var stored) ? stored : JobPriority.Background; _priority = Priorities.First(p => p.Value == priority); _catchUp = schedule?.CatchUp ?? true; @@ -196,7 +193,8 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel /// The name shown for a system schedule, which is not edited. public string SystemName => _schedule is null ? string.Empty : ScheduleText.Name(_schedule); - public IReadOnlyList ActionOptions { get; } + /// Every action, with whether this PC runs it as last read; built again when that or the UI language changes. + public IReadOnlyList ActionOptions { get; private set; } public ScheduleActionOption SelectedAction { @@ -242,7 +240,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel public ScheduleField Every { get; } - public IReadOnlyList> Units { get; } + public IReadOnlyList> Units { get; private set; } public SettingsOption SelectedUnit { @@ -320,7 +318,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel // ---------------- Options ---------------- - public IReadOnlyList> Priorities { get; } + public IReadOnlyList> Priorities { get; private set; } public SettingsOption SelectedPriority { @@ -434,14 +432,52 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel internal UpdateScheduleRequest BuildUpdate() => new(IsSystem ? null : Name.Text.Trim(), IsSystem ? null : _action.Name, Recurrence(), Parameters(), _catchUp, JobWire.Priority(_priority.Value), _enabled); + /// Whether this PC runs each action was read again (). + internal void RefreshActions() => RebuildActionOptions(); + protected override void OnLanguageChanged() { foreach (var field in new[] { Name, Every, Time, DayOfMonth, OlderThan, Percent, Keep }) field.Refresh(); foreach (var day in Days) day.Refresh(); foreach (var step in Steps) step.Refresh(); + // The dropdowns' choices carry their labels: new ones in the new language, the same values chosen. Each list is + // announced before its choice, so a dropdown finds the choice among its items. + RebuildActionOptions(); + Units = BuildUnits(); + _unit = Units.First(u => u.Value == _unit.Value); + OnPropertyChanged(nameof(Units)); + OnPropertyChanged(nameof(SelectedUnit)); + Priorities = BuildPriorities(); + _priority = Priorities.First(p => p.Value == _priority.Value); + OnPropertyChanged(nameof(Priorities)); + OnPropertyChanged(nameof(SelectedPriority)); base.OnLanguageChanged(); } + /// The actions again, from the owner's last read; the chosen one stays chosen. + private void RebuildActionOptions() + { + ActionOptions = BuildActionOptions(); + _action = ActionOptions.FirstOrDefault(o => o.Name == _action.Name) ?? _action; + OnPropertyChanged(nameof(ActionOptions)); + OnPropertyChanged(nameof(SelectedAction)); + OnPropertyChanged(nameof(ActionToolTip)); + } + + private ScheduleActionOption[] BuildActionOptions() + { + var available = _owner.Actions; + return [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info + ? new ScheduleActionOption(a, info.Available, info.Reason) + : new ScheduleActionOption(a, true, null))]; + } + + private static SettingsOption[] BuildUnits() => + [.. Enum.GetValues().Select(u => new SettingsOption(u, Loc.L("Jobs.Editor.Unit." + u)))]; + + private static SettingsOption[] BuildPriorities() => + [.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption(p, ScheduleText.Priority(p)))]; + private bool IsVerify => _action.Name == ScheduleActions.Verify; /// Save: the schedule as the fields hold it; the editor closes once it is stored, or says why it was not. diff --git a/src/Chronos.App/Jobs/ScheduleRowViewModel.cs b/src/Chronos.App/Jobs/ScheduleRowViewModel.cs index e7942033..a9efc077 100644 --- a/src/Chronos.App/Jobs/ScheduleRowViewModel.cs +++ b/src/Chronos.App/Jobs/ScheduleRowViewModel.cs @@ -18,6 +18,7 @@ public sealed class ScheduleRowViewModel : ObservableObject private readonly SchedulesViewModel _owner; private ScheduleDto _schedule; private Job? _lastJob; + private long _lastJobStamp; private bool _isEnabled; internal ScheduleRowViewModel(ScheduleDto schedule, SchedulesViewModel owner) @@ -105,16 +106,40 @@ public sealed class ScheduleRowViewModel : ObservableObject /// A newer copy of the schedule (an edit, a run, a correction of its next run). internal void Update(ScheduleDto schedule) { - if (schedule.LastJobId != _schedule.LastJobId) _lastJob = null; + if (schedule.LastJobId != _schedule.LastJobId) + { + // A read of the previous job no longer applies. + _lastJob = null; + _lastJobStamp++; + } _schedule = schedule; _isEnabled = schedule.Enabled; OnAllPropertiesChanged(); } - /// The job the last run queued changed (or was read): the last result follows its state. + /// The job the last run queued changed (live, from the engine): the last result follows its state. internal void SetLastJob(Job? job) { if (job is not null && job.Id != _schedule.LastJobId) return; + _lastJobStamp++; + ShowLastJob(job); + } + + /// + /// A read of the last job from the index starts; its result applies only while nothing newer arrived (a live change, + /// another job, a later read): see . + /// + internal long BeginLastJobRead() => ++_lastJobStamp; + + /// The last job as the read begun at found it; ignored when that read is stale. + internal void SetLoadedLastJob(Job? job, long read) + { + if (read != _lastJobStamp || (job is not null && job.Id != _schedule.LastJobId)) return; + ShowLastJob(job); + } + + private void ShowLastJob(Job? job) + { _lastJob = job; OnPropertyChanged(nameof(LastJob)); OnPropertyChanged(nameof(LastText)); diff --git a/src/Chronos.App/Jobs/ScheduleText.cs b/src/Chronos.App/Jobs/ScheduleText.cs index da74732f..b3064aae 100644 --- a/src/Chronos.App/Jobs/ScheduleText.cs +++ b/src/Chronos.App/Jobs/ScheduleText.cs @@ -62,9 +62,15 @@ public static class ScheduleText }; } - /// "Mon, Thu": the days in the order of the week, short names of the UI language. - public static string Days(IEnumerable days) => - days.Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b)); + /// + /// "Mon, Thu": the days in the order of the UI language's week, from its first day as the editor lists them (Sunday + /// first in English, Monday first in Italian), short names of the UI language. + /// + public static string Days(IEnumerable days) + { + var first = (int)Loc.Culture.DateTimeFormat.FirstDayOfWeek; + return days.OrderBy(d => ((int)d - first + 7) % 7).Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b)); + } /// "Mon" in the UI language. public static string DayShort(DayOfWeek day) => Loc.Culture.DateTimeFormat.GetAbbreviatedDayName(day); diff --git a/src/Chronos.App/Jobs/SchedulesViewModel.cs b/src/Chronos.App/Jobs/SchedulesViewModel.cs index e2349dab..e688e165 100644 --- a/src/Chronos.App/Jobs/SchedulesViewModel.cs +++ b/src/Chronos.App/Jobs/SchedulesViewModel.cs @@ -241,6 +241,30 @@ public sealed class SchedulesViewModel : LocalizedViewModel if (_selected is not null) await LoadRunsAsync(); } + /// + /// Reads again whether this PC runs each action (Jobs › Scheduled is shown: proxies may have been turned on or off, + /// another archive chosen): the rows' Run now and tooltips, and the actions of the editor, follow it. + /// + public async Task RefreshActionsAsync() + { + if (_attached is not { } scheduler) return; + SchedulesDto list; + try + { + list = await Task.Run(() => scheduler.ListAsync()); + } + catch (Exception ex) when (ex is DatabaseException or IOException or InvalidOperationException) + { + Log.Warning("schedules", "The actions could not be read again", ex); + return; + } + _actions = list.Actions; + _steps = list.Steps ?? []; + foreach (var row in Rows) row.Refresh(); + _editor?.RefreshActions(); + CommandManager.InvalidateRequerySuggested(); + } + /// A job changed (UI thread, from the Jobs screen's flush): the last result and the last runs follow it. public void OnJob(Job job) { @@ -287,6 +311,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel } Apply(run.Schedule); if (run.Outcome == ScheduleOutcome.Queued) return; + // This PC no longer runs the action: the row says so from now on. + if (run.Outcome == ScheduleOutcome.Unavailable) await RefreshActionsAsync(); _notify(Loc.L("Jobs.Row.Name", row.Name, ScheduleText.Outcome(run.Outcome, null)), ScheduleText.OutcomeToolTip(run.Outcome, run.Schedule.LastRun, null), ScheduleOutcome.IsFailed(run.Outcome, out _) || run.Outcome == ScheduleOutcome.Unavailable); } @@ -326,7 +352,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel IsDestructive = true, }); if (!confirmed) return; - var outcome = await Call(() => scheduler.DeleteAsync(row.Id)); + // Nullable: a failed call is null, not the enum's first value (Deleted), so its row stays. + var outcome = await Call(async () => await scheduler.DeleteAsync(row.Id)); if (outcome is ScheduleDeleteOutcome.Deleted or ScheduleDeleteOutcome.NotFound) Remove(row.Id); } @@ -443,12 +470,14 @@ public sealed class SchedulesViewModel : LocalizedViewModel RaiseState(); } + /// Reads the job of the schedule's last run; a change of it announced meanwhile, or a later read, wins. private async Task LoadLastJobAsync(ScheduleRowViewModel row) { if (row.Schedule.LastJobId is not { } id || _database() is not { } db) return; + var read = row.BeginLastJobRead(); try { - row.SetLastJob(await db.Jobs.GetAsync(id)); + row.SetLoadedLastJob(await db.Jobs.GetAsync(id), read); } catch (DatabaseException ex) { @@ -479,7 +508,10 @@ public sealed class SchedulesViewModel : LocalizedViewModel RaiseRuns(); } - /// Runs a scheduler call off the UI thread; a failure becomes a toast and null. + /// + /// Runs a scheduler call off the UI thread; a failure becomes a toast and null (for a value type, ask for its nullable + /// type: its default would read as a result). + /// private async Task Call(Func> call) { try diff --git a/src/Chronos.App/Sections/ArchiveViewModel.cs b/src/Chronos.App/Sections/ArchiveViewModel.cs index 0a1991b3..ba6e7f17 100644 --- a/src/Chronos.App/Sections/ArchiveViewModel.cs +++ b/src/Chronos.App/Sections/ArchiveViewModel.cs @@ -189,7 +189,7 @@ public sealed class ArchiveViewModel : SectionViewModel public ICommand BackupCommand { get; } - /// "Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a daily copy is compared and restored (§6.2). + /// "Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a backup copy is compared and restored (§6.2). public ICommand RestoreCommand { get; } public ICommand MaintenanceCommand { get; } diff --git a/src/Chronos.App/Sections/JobsViewModel.cs b/src/Chronos.App/Sections/JobsViewModel.cs index 89808a01..02cd1ac8 100644 --- a/src/Chronos.App/Sections/JobsViewModel.cs +++ b/src/Chronos.App/Sections/JobsViewModel.cs @@ -113,7 +113,7 @@ public sealed class JobsViewModel : SectionViewModel /// Jobs › Scheduled. public SchedulesViewModel Schedules { get; } - /// 0 = Queue, 1 = Scheduled (the segmented control's index). + /// 0 = Queue, 1 = Scheduled (the segmented control's index). Scheduled, shown, reads the actions' availability again. public int TabIndex { get => _tabIndex; @@ -122,6 +122,7 @@ public sealed class JobsViewModel : SectionViewModel if (value is < 0 or > 1 || !Set(ref _tabIndex, value)) return; OnPropertyChanged(nameof(IsQueue)); OnPropertyChanged(nameof(IsScheduled)); + if (IsScheduled) _ = Schedules.RefreshActionsAsync(); } } @@ -279,9 +280,13 @@ public sealed class JobsViewModel : SectionViewModel UpdateShell(); } - /// Failures seen on this screen no longer count on the rail. + /// + /// Failures seen on this screen no longer count on the rail; back on Scheduled (from Settings, say), the actions' + /// availability is read again. + /// protected override void OnActivated() { + if (IsScheduled) _ = Schedules.RefreshActionsAsync(); if (_unseenFailures.Count == 0) return; _unseenFailures.Clear(); UpdateShell(); diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml index 07f1b56c..c6141a23 100644 --- a/src/Chronos.App/Sections/SettingsView.xaml +++ b/src/Chronos.App/Sections/SettingsView.xaml @@ -646,7 +646,7 @@