Owner review 2, R10 on the desktop: every timer that queued work out of sight is now a visible, editable schedule of this PC. - DesktopScheduleHost implements IScheduleHost: the PC's time zone, the archive at Settings › Archive's folder (refreshed from archive.json, none while it is offline), and three system schedules: archive-scan (every:<ScanIntervalMinutes>m, seeded once from the old setting, no catch-up), index-backup (every day with catch-up, replacing DatabaseBackups.RunDailyAsync) and housekeeping (daily 04:00 with catch-up: job history 90 days and the new cache-trim step). - AppServices starts the Scheduler after the engine, once the archive was reopened; an unplugged archive is looked for every minute and the scheduler woken when it is back. The rescan loop and the daily backup loop are gone; ApplyJobSettings wakes the scheduler. - CacheStore.Trim brings the cache to Settings › Storage › Cache limit, oldest files first, skipping files in use and the proxies, render-node and server-import folders; CacheTrimStep runs it as a clean-up step. - Jobs gets a Queue | Scheduled segmented control. Scheduled lists the schedules (switch, name, action, when, next run, last result) with Run now, Edit, Reset (system) or Delete (user's, confirmed), the selected schedule's last runs with Show in queue, and an in-window editor that checks every field with the scheduler's limits. Jobs a schedule queued carry a "Scheduled" pill; the history line follows the housekeeping's job-history days. - JobNotices: a scheduled background run raises a toast only when it fails (upkeep stays silent). - Settings › Archive › Rescan every is removed; ScanIntervalMinutes stays only as the seed. Strings in en and it; the others are retranslated. - The capture shows jobs-scheduled and jobs-schedule-editor on a stopped scheduler clock with sample schedules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e25d812feb3f417cb9251c748c29e8035fd9b03c)
76 lines
2.9 KiB
C#
76 lines
2.9 KiB
C#
using System.ComponentModel;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using System.Windows.Threading;
|
||
using Chronos.App.Jobs;
|
||
|
||
namespace Chronos.App.Sections;
|
||
|
||
public partial class JobsView : UserControl
|
||
{
|
||
private JobsViewModel? _model;
|
||
private IInputElement? _beforeDialog;
|
||
|
||
public JobsView()
|
||
{
|
||
InitializeComponent();
|
||
DataContextChanged += OnDataContextChanged;
|
||
}
|
||
|
||
/// <summary>Loads older history when the list scrolls near its end.</summary>
|
||
private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
|
||
{
|
||
if (DataContext is not JobsViewModel vm || e.ExtentHeight <= 0) return;
|
||
if (e.VerticalOffset + e.ViewportHeight >= e.ExtentHeight - Math.Max(e.ViewportHeight, 200)) _ = vm.LoadMoreAsync();
|
||
}
|
||
|
||
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||
{
|
||
if (_model is not null)
|
||
{
|
||
_model.RowRevealRequested -= OnRevealRequested;
|
||
_model.Schedules.PropertyChanged -= OnSchedulesChanged;
|
||
}
|
||
_model = e.NewValue as JobsViewModel;
|
||
if (_model is not null)
|
||
{
|
||
_model.RowRevealRequested += OnRevealRequested;
|
||
_model.Schedules.PropertyChanged += OnSchedulesChanged;
|
||
}
|
||
}
|
||
|
||
/// <summary>A job shown from Jobs › Scheduled: its row comes into view (the list is visible again by then) and takes the keyboard.</summary>
|
||
private void OnRevealRequested(JobRowViewModel row) =>
|
||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>
|
||
{
|
||
JobList.ScrollIntoView(row);
|
||
JobList.UpdateLayout();
|
||
if (JobList.ItemContainerGenerator.ContainerFromItem(row) is ListBoxItem item) item.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||
});
|
||
|
||
/// <summary>
|
||
/// The schedule editor takes the keyboard when it opens (its first field); when it closes, the keyboard goes back to the
|
||
/// control that opened it while that can still take it.
|
||
/// </summary>
|
||
private void OnSchedulesChanged(object? sender, PropertyChangedEventArgs e)
|
||
{
|
||
if (e.PropertyName != nameof(SchedulesViewModel.Editor) || _model is not { } model) return;
|
||
if (model.Schedules.Editor is not null)
|
||
{
|
||
if (!IsVisible) return;
|
||
_beforeDialog ??= Keyboard.FocusedElement is Visual focused && IsAncestorOf(focused) ? Keyboard.FocusedElement : null;
|
||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
|
||
return;
|
||
}
|
||
var back = _beforeDialog;
|
||
_beforeDialog = null;
|
||
if (!IsVisible) return;
|
||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
|
||
{
|
||
if (back is UIElement { IsVisible: true, IsEnabled: true, Focusable: true } element) element.Focus();
|
||
});
|
||
}
|
||
}
|