diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx
index 3be6f60e..af279970 100644
--- a/i18n/en/Tooltips.resx
+++ b/i18n/en/Tooltips.resx
@@ -919,7 +919,7 @@
Try this file again nowSelect Sequence to choose oneAddress of the Chronos Server, such as https://nas.local:8443
- Server, sign in, bandwidth, startup, tray
+ Server, sign in, bandwidth, startup, tray, updatesShow the first file that failed · press Enter on it to try againCheck the server certificate and sign inSign out and forget the saved token
@@ -929,6 +929,17 @@
Add every file to one existing sequenceThe server splits the files into sessions and creates the sequencesRemember this certificate; trust it only if the fingerprint matches the one on the server
+ A newer Chronos release exists · Download fetches the setup
+ Stop the download; Download resumes it later from where it stopped
+ Ask the public releases page for a newer version · a few seconds
+ Look for a newer Chronos release when the Uploader starts · skipped when Chronos Desktop is installed alongside, whose own notice covers the same setup
+ Download the setup, check it against the release's SHA-256 list and show it in Explorer · {0}
+ Open the page of this release in the browser
+ Download the portable zip, check it against the release's SHA-256 list and show it in Explorer · {0}
+ The releases page could not be reached · try again later
+ Show the verified zip in Explorer; close Chronos and the Uploader and unpack it over this folder to upgrade. The data folder is kept
+ Show the verified setup in Explorer; close the Uploader and run it to upgrade. Queue and settings are kept
+ You run the newest stable releaseYour user name on the Chronos ServerChecked every {0}; a file is uploaded once it has stopped growing · click to change or removeThe folder cannot be reached; it is checked again every {0} · click to change or remove
diff --git a/i18n/en/Uploader.resx b/i18n/en/Uploader.resx
index 320070df..8a1a72ab 100644
--- a/i18n/en/Uploader.resx
+++ b/i18n/en/Uploader.resx
@@ -103,6 +103,21 @@
Compare this fingerprint with the one shown on the server.longTrust this server?{0}/s
+ Version {0} available
+ Cancel
+ Check now
+ Check on start
+ Checking…
+ Download
+ Download failed
+ Downloading {0:P0}
+ Check failed
+ Downloading…
+ Download not verified
+ Version {0} downloaded
+ Show setup
+ Updates
+ Up to date{0} · every {1}Every {0}every {0}
diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx
index 4a6a5ca8..ad0b1452 100644
--- a/i18n/it/Tooltips.it.resx
+++ b/i18n/it/Tooltips.it.resx
@@ -1016,7 +1016,7 @@
Riprova subito questo fileSeleziona Sequenza per sceglierne unaIndirizzo del Chronos Server, ad esempio https://nas.local:8443
- Server, accesso, banda, avvio, area di notifica
+ Server, accesso, banda, avvio, area di notifica, aggiornamentiMostra il primo file non riuscito · premi Invio per riprovarloControlla il certificato del server e accediEsci e dimentica il token salvato
@@ -1026,6 +1026,17 @@
Aggiungi tutti i file a una sequenza esistenteIl server divide i file in sessioni e crea le sequenzeRicorda questo certificato; accettalo solo se l'impronta coincide con quella sul server
+ Esiste una versione più recente di Chronos · Scarica prende l'installer
+ Interrompe il download; Scarica lo riprende in seguito dal punto in cui si è fermato
+ Chiede alla pagina pubblica delle versioni se ne esiste una più recente · pochi secondi
+ Cerca una versione più recente di Chronos all'avvio dell'Uploader · saltato quando accanto è installato Chronos Desktop, il cui avviso copre lo stesso installer
+ Scarica l'installer, lo confronta con l'elenco SHA-256 della versione e lo mostra in Esplora file · {0}
+ Apre la pagina di questa versione nel browser
+ Scarica lo zip portatile, lo confronta con l'elenco SHA-256 della versione e lo mostra in Esplora file · {0}
+ Non è stato possibile raggiungere la pagina delle versioni · riprova più tardi
+ Mostra in Esplora file lo zip verificato; chiudi Chronos e l'Uploader ed estrailo sopra questa cartella per aggiornare. La cartella dei dati resta invariata
+ Mostra in Esplora file l'installer verificato; chiudi l'Uploader ed eseguilo per aggiornare. Coda e impostazioni restano invariate
+ Usi la versione stabile più recenteIl tuo nome utente sul Chronos ServerControllata ogni {0}; un file viene inviato quando smette di crescere · fai clic per modificare o rimuovereLa cartella non è raggiungibile; viene ricontrollata ogni {0} · fai clic per modificare o rimuovere
diff --git a/i18n/it/Uploader.it.resx b/i18n/it/Uploader.it.resx
index c32430fd..5487e793 100644
--- a/i18n/it/Uploader.it.resx
+++ b/i18n/it/Uploader.it.resx
@@ -101,6 +101,21 @@
Confronta questa impronta con quella mostrata sul server.Accettare questo server?{0}/s
+ Versione {0} disponibile
+ Annulla
+ Verifica ora
+ Verifica all'avvio
+ Verifica in corso…
+ Scarica
+ Download non riuscito
+ Download in corso {0:P0}
+ Verifica non riuscita
+ Download in corso…
+ Download non verificato
+ Versione {0} scaricata
+ Mostra installer
+ Aggiornamenti
+ Aggiornato{0} · ogni {1}Ogni {0}ogni {0}
diff --git a/src/Chronos.Uploader/App.xaml.cs b/src/Chronos.Uploader/App.xaml.cs
index dfd00a06..8c222ec2 100644
--- a/src/Chronos.Uploader/App.xaml.cs
+++ b/src/Chronos.Uploader/App.xaml.cs
@@ -82,6 +82,7 @@ public partial class App : Application
UpdateTray();
UpdateDiscovery();
if (command.Paths.Count > 0) _ = _vm.EnqueueAsync(command.Paths);
+ _ = _vm.Updates.CheckOnStartAsync(_environment.HasDesktopBeside);
if (command.StartInTray && _settings.MinimizeToTray) return;
if (command.StartInTray) _window!.WindowState = WindowState.Minimized;
@@ -122,7 +123,10 @@ public partial class App : Application
var startup = new RunKeyStartupRegistration();
startup.Refresh();
var dialogs = new UploaderDialogs();
- _vm = new MainViewModel(new UploaderServices(settings, SaveSettings, _session, _queue, _engine, startup, dialogs, _watch, _memory, environment.LogDirectory));
+ _vm = new MainViewModel(new UploaderServices(settings, SaveSettings, _session, _queue, _engine, startup, dialogs, _watch, _memory, environment.LogDirectory)
+ {
+ Updates = UploaderUpdates.Host(environment.IsPortable),
+ });
_window = new Shell.MainWindow(_vm, settings);
dialogs.Owner = _window;
MainWindow = _window;
diff --git a/src/Chronos.Uploader/DesignTime/SampleData.cs b/src/Chronos.Uploader/DesignTime/SampleData.cs
index 8664e9be..9d1f9b32 100644
--- a/src/Chronos.Uploader/DesignTime/SampleData.cs
+++ b/src/Chronos.Uploader/DesignTime/SampleData.cs
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
+using Chronos.Core.Updates;
using Chronos.Protocol;
using Chronos.Uploader.Infrastructure;
using Chronos.Uploader.Server;
@@ -19,6 +20,7 @@ public sealed class SampleData
{
private const int FileCount = 4_812;
private const long FileSize = 20_000_000;
+ private const string RunningVersion = "1.0.0";
/// The sample's "now" (when the failed file failed): fixed, so the screenshots are the same on any day.
private static readonly DateTime Now = new(2026, 9, 28, 19, 2, 0, DateTimeKind.Utc);
@@ -51,7 +53,11 @@ public sealed class SampleData
_session.BandwidthLimit = Settings.BandwidthLimit;
_vm = new MainViewModel(new UploaderServices(
Settings, () => { }, _session, _queue, new SampleEngine(_queue), startup ?? new SampleStartup(), new UploaderDialogs(),
- new WatchFolderService(memory, _queue.ContainsPath), memory, string.Empty));
+ new WatchFolderService(memory, _queue.ContainsPath), memory, string.Empty)
+ {
+ // A fixed running version, so the update notice reads the same whatever this build's version is.
+ Updates = UploaderUpdates.Offline(RunningVersion),
+ });
foreach (var w in _vm.WatchFolders) w.IsAvailable = true;
// A disconnected drive: its chip shows the hollow ring and wraps to a second line.
_vm.WatchFolders[^1].IsAvailable = false;
@@ -79,6 +85,20 @@ public sealed class SampleData
_vm.RefreshQueue();
}
+ /// The settings panel's update notice: a newer release with its setup and checksums, so Download is offered.
+ public void ShowUpdate()
+ {
+ const string Base = "https://gitea.example/BalboSoft/Chronos/releases/download/v1.1.0/";
+ _vm!.Updates.SetResult(new ReleaseInfo(new Version(1, 1, 0), "v1.1.0", "https://gitea.example/BalboSoft/Chronos/releases/tag/v1.1.0")
+ {
+ Assets =
+ [
+ new ReleaseAsset("Chronos-Setup-1.1.0.exe", Base + "Chronos-Setup-1.1.0.exe", 92_400_000),
+ new ReleaseAsset(UpdateDownload.ChecksumsName, Base + UpdateDownload.ChecksumsName, 300),
+ ],
+ });
+ }
+
private void FillQueue()
{
var batch = new UploadBatch { Id = Guid.CreateVersion7(), Mode = UploadTargetMode.Sessions };
diff --git a/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs b/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs
index 4d84a28b..c54c8f6c 100644
--- a/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs
+++ b/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs
@@ -9,9 +9,14 @@ namespace Chronos.Uploader.Infrastructure;
///
public sealed class UploaderEnvironment
{
- private UploaderEnvironment(string dataDirectory)
+ /// The desktop program's file name; the single setup installs it in the Uploader's own folder.
+ public const string DesktopExecutable = "Chronos.exe";
+
+ private UploaderEnvironment(string dataDirectory, bool isPortable, bool hasDesktopBeside)
{
DataDirectory = dataDirectory;
+ IsPortable = isPortable;
+ HasDesktopBeside = hasDesktopBeside;
Directory.CreateDirectory(DataDirectory);
Directory.CreateDirectory(LogDirectory);
}
@@ -19,6 +24,15 @@ public sealed class UploaderEnvironment
public string DataDirectory { get; }
public string LogDirectory => Path.Combine(DataDirectory, "logs");
+ /// A portable copy (portable.txt beside the executable): its update is the portable zip, not the setup.
+ public bool IsPortable { get; }
+
+ ///
+ /// Chronos Desktop sits in the same folder: its own update notice covers the same setup, so the Uploader skips its
+ /// start-up check (Check now still works).
+ ///
+ public bool HasDesktopBeside { get; }
+
/// Settings, DPAPI-protected token and trusted certificate fingerprints.
public string SettingsPath => Path.Combine(DataDirectory, "uploader.json");
@@ -31,8 +45,12 @@ public sealed class UploaderEnvironment
public static UploaderEnvironment Detect()
{
var exeDir = AppContext.BaseDirectory;
- if (File.Exists(Path.Combine(exeDir, "portable.txt"))) return new UploaderEnvironment(Path.Combine(exeDir, "data"));
+ var desktop = IsDesktopBeside(exeDir);
+ if (File.Exists(Path.Combine(exeDir, "portable.txt"))) return new UploaderEnvironment(Path.Combine(exeDir, "data"), isPortable: true, desktop);
var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
- return new UploaderEnvironment(Path.Combine(local, "Chronos"));
+ return new UploaderEnvironment(Path.Combine(local, "Chronos"), isPortable: false, desktop);
}
+
+ /// True when is in .
+ public static bool IsDesktopBeside(string folder) => File.Exists(Path.Combine(folder, DesktopExecutable));
}
diff --git a/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs b/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs
index 0bcb3cf9..cd48f102 100644
--- a/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs
+++ b/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs
@@ -27,6 +27,10 @@ public sealed class UploaderSettings
public int BandwidthLimit { get; set; }
public bool MinimizeToTray { get; set; } = true;
+
+ /// Look for a newer Chronos release on start (opt-out, BRIEF §18); a 1.0 file without the key keeps it on.
+ public bool CheckForUpdates { get; set; } = true;
+
public bool DeleteAfterUpload { get; set; }
public UploadTargetMode Target { get; set; } = UploadTargetMode.Sessions;
public Guid? TargetSequenceId { get; set; }
diff --git a/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs b/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs
new file mode 100644
index 00000000..6d7d8f3a
--- /dev/null
+++ b/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs
@@ -0,0 +1,46 @@
+using System.IO;
+using System.Net.Http;
+using System.Reflection;
+using Chronos.Core.Updates;
+using Chronos.Ui.Updates;
+using Chronos.Uploader.Interop;
+
+namespace Chronos.Uploader.Infrastructure;
+
+///
+/// The Uploader's side of the shared update notice (BRIEF §18, owner review 5): the same releases feed, the same single
+/// setup (or the portable zip of a portable copy) and the same %TEMP%\Chronos\updates folder as the desktop.
+///
+public static class UploaderUpdates
+{
+ private static readonly Lazy Http = new(() => new HttpClient { Timeout = TimeSpan.FromSeconds(20) });
+
+ /// Update packages are large: their download fails when it stalls (), never after a fixed total time.
+ private static readonly Lazy DownloadHttp = new(() => new HttpClient { Timeout = Timeout.InfiniteTimeSpan });
+
+ /// The informational version of this build, such as "1.1.0" or "1.1.0-rc.1".
+ public static string VersionText { get; } =
+ typeof(UploaderUpdates).Assembly.GetCustomAttribute()?.InformationalVersion ?? "0.0.0";
+
+ /// The live host: the public releases repository, the shell's browser and Explorer.
+ public static UpdateHost Host(bool portable) =>
+ Host(Http.Value, DownloadHttp.Value, ProductLinks.Repository, VersionText, portable, UpdateDownload.Root(Path.GetTempPath()), ShellActions.OpenUrl,
+ ShellActions.Reveal);
+
+ /// A host over the given clients and releases repository ("https://host/owner/name"); tests pass a fake transport.
+ public static UpdateHost Host(HttpClient http, HttpClient downloadHttp, string repository, string versionText, bool portable, string downloadRoot,
+ Action openUrl, Action reveal) =>
+ new(UpdateCheck.RunningVersion(versionText), IsCapture: false, portable,
+ ct => UpdateCheck.FetchAsync(http, ProductLinks.StableReleasesApiOf(repository), repository, versionText, ct),
+ (release, progress, ct) => UpdateDownload.DownloadAsync(downloadHttp, release, portable, downloadRoot, versionText, progress, UpdateDownload.IdleTimeout, ct),
+ openUrl, reveal)
+ {
+ RunningIsPrerelease = UpdateCheck.IsPrerelease(versionText),
+ };
+
+ /// A host that never touches the network or the shell (--capture, design time).
+ public static UpdateHost Offline(string versionText) =>
+ new(UpdateCheck.RunningVersion(versionText), IsCapture: true, IsPortable: false,
+ _ => Task.FromResult(null), (_, _, _) => Task.FromException(new InvalidOperationException("No download in a capture run.")),
+ _ => { }, _ => { });
+}
diff --git a/src/Chronos.Uploader/Interop/ShellActions.cs b/src/Chronos.Uploader/Interop/ShellActions.cs
new file mode 100644
index 00000000..d49327c4
--- /dev/null
+++ b/src/Chronos.Uploader/Interop/ShellActions.cs
@@ -0,0 +1,55 @@
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.InteropServices;
+using Chronos.Core.Diagnostics;
+
+namespace Chronos.Uploader.Interop;
+
+///
+/// The two shell actions of the update notice (BRIEF §8.6): open an https link in the browser and show a file selected
+/// in Explorer. Nothing else is started; the verified setup is run by the user.
+///
+public static partial class ShellActions
+{
+ /// Opens an absolute https link with the shell's "open" verb; anything else is ignored.
+ public static void OpenUrl(string url)
+ {
+ if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttps) return;
+ try
+ {
+ using var _ = Process.Start(new ProcessStartInfo(uri.AbsoluteUri) { UseShellExecute = true, Verb = "open" });
+ }
+ catch (Exception ex) when (ex is Win32Exception or InvalidOperationException)
+ {
+ Log.Warning("shell", $"The shell could not open {uri.AbsoluteUri}", ex);
+ }
+ }
+
+ /// Shows the file selected in its Explorer folder (SHOpenFolderAndSelectItems); a missing file is ignored.
+ public static void Reveal(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) return;
+ var full = Path.GetFullPath(path);
+ if (SHParseDisplayName(full, 0, out var itemList, 0, out _) < 0)
+ {
+ Log.Warning("shell", $"Explorer could not show {full}");
+ return;
+ }
+ try
+ {
+ // With no child items the absolute ID list names the item to select; Explorer opens its parent.
+ if (SHOpenFolderAndSelectItems(itemList, 0, 0, 0) < 0) Log.Warning("shell", $"Explorer could not show {full}");
+ }
+ finally
+ {
+ Marshal.FreeCoTaskMem(itemList);
+ }
+ }
+
+ [LibraryImport("shell32.dll", StringMarshalling = StringMarshalling.Utf16)]
+ private static partial int SHParseDisplayName(string name, nint bindContext, out nint itemIdList, uint attributesIn, out uint attributesOut);
+
+ [LibraryImport("shell32.dll")]
+ private static partial int SHOpenFolderAndSelectItems(nint folder, uint count, nint items, uint flags);
+}
diff --git a/src/Chronos.Uploader/Shell/MainViewModel.cs b/src/Chronos.Uploader/Shell/MainViewModel.cs
index 0dbdd83d..43aa2c0d 100644
--- a/src/Chronos.Uploader/Shell/MainViewModel.cs
+++ b/src/Chronos.Uploader/Shell/MainViewModel.cs
@@ -7,8 +7,10 @@ using System.Windows.Input;
using System.Windows.Threading;
using Chronos.Core.Diagnostics;
using Chronos.Core.Localization;
+using Chronos.Core.Updates;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
+using Chronos.Ui.Updates;
using Chronos.Uploader.Infrastructure;
using Chronos.Uploader.Server;
using Chronos.Uploader.Sources;
@@ -32,7 +34,11 @@ public sealed record UploaderServices(
IUploaderDialogs Dialogs,
WatchFolderService Watch,
ProcessedFileMemory Memory,
- string LogDirectory);
+ string LogDirectory)
+{
+ /// The update notice's network and shell; null never touches either (capture, tests).
+ public UpdateHost? Updates { get; init; }
+}
/// State of the uploader window (BRIEF §15, mockup Uploader.html).
public sealed class MainViewModel : LocalizedViewModel
@@ -65,6 +71,8 @@ public sealed class MainViewModel : LocalizedViewModel
if (e.PropertyName == nameof(ConnectViewModel.IsSigningIn)) OnPropertyChanged(nameof(IsConnectVisible));
};
foreach (var w in services.Settings.WatchFolders) WatchFolders.Add(NewWatchFolder(w.Path, w.IntervalSeconds));
+ Updates = new UpdatesViewModel(services.Updates ?? UploaderUpdates.Offline(UploaderUpdates.VersionText), services.Settings, services.SaveSettings);
+ Updates.Found += OnUpdateFound;
OpenSettingsCommand = new RelayCommand(() => IsSettingsOpen = true);
CloseSettingsCommand = new RelayCommand(() => IsSettingsOpen = false);
@@ -105,6 +113,9 @@ public sealed class MainViewModel : LocalizedViewModel
public ConnectViewModel Connect { get; }
+ /// The Updates row of the settings panel.
+ public UpdatesViewModel Updates { get; }
+
/// In-window notifications; the window forwards them to its .
public ObservableCollection PendingToasts { get; } = [];
@@ -416,6 +427,8 @@ public sealed class MainViewModel : LocalizedViewModel
_s.Session.PropertyChanged -= OnSessionChanged;
_s.Session.SessionEnded -= OnSessionEnded;
_s.Engine.Drained -= OnDrained;
+ Updates.Found -= OnUpdateFound;
+ Updates.Dispose();
base.Dispose();
}
@@ -592,6 +605,11 @@ public sealed class MainViewModel : LocalizedViewModel
if (confirmed > 0) UploadsCompleted?.Invoke(confirmed);
}
+ /// The start-up check found a newer release: one sentence, and Download as its action.
+ private void OnUpdateFound(ReleaseInfo release) =>
+ ShowToast(Loc.L("Uploader.Updates.Available", UpdateCheck.Display(release.Version)), Loc.L("Uploader.Updates.Download"),
+ Updates.DownloadToolTip, Updates.DownloadCommand);
+
/// One sentence and at most one action; marks a failure or refusal, which screen readers say at once.
private void ShowToast(string title, string? actionText = null, string? actionToolTip = null, ICommand? action = null, bool isError = false) =>
PendingToasts.Add(new Toast { Title = title, ActionText = actionText, ActionToolTip = actionToolTip, ActionCommand = action, IsError = isError });
diff --git a/src/Chronos.Uploader/Shell/MainWindow.xaml b/src/Chronos.Uploader/Shell/MainWindow.xaml
index c4b92715..b2735e5d 100644
--- a/src/Chronos.Uploader/Shell/MainWindow.xaml
+++ b/src/Chronos.Uploader/Shell/MainWindow.xaml
@@ -471,6 +471,8 @@
+
+
@@ -501,6 +503,26 @@
ToolTip="{l:Loc Tooltips.Uploader.DeleteSource}" VerticalAlignment="Center">
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Chronos.Uploader/Shell/MainWindow.xaml.cs b/src/Chronos.Uploader/Shell/MainWindow.xaml.cs
index 9100bd40..a3d86560 100644
--- a/src/Chronos.Uploader/Shell/MainWindow.xaml.cs
+++ b/src/Chronos.Uploader/Shell/MainWindow.xaml.cs
@@ -35,6 +35,11 @@ public sealed partial class MainWindow : ChronosWindow
vm.PendingToasts.CollectionChanged += OnToastRequested;
vm.PropertyChanged += OnViewModelChanged;
vm.Connect.PropertyChanged += OnConnectChanged;
+ // Each new update state is announced once, not each percent of a download.
+ vm.Updates.PropertyChanged += (_, e) =>
+ {
+ if (e.PropertyName == nameof(UpdatesViewModel.State)) Dispatcher.BeginInvoke(DispatcherPriority.Background, () => Announce(UpdateStatus));
+ };
vm.SignInRequested += (_, _) => FocusLater(Password);
PreviewKeyDown += OnPreviewKeyDown;
Loaded += (_, _) => FocusStart();
diff --git a/src/Chronos.Uploader/Shell/ScreenCapture.cs b/src/Chronos.Uploader/Shell/ScreenCapture.cs
index 527db918..29d07f76 100644
--- a/src/Chronos.Uploader/Shell/ScreenCapture.cs
+++ b/src/Chronos.Uploader/Shell/ScreenCapture.cs
@@ -78,6 +78,7 @@ public static class ScreenCapture
Save(window, Path.Combine(directory, $"uploader-connect{suffix}.png"));
sample.ShowQueue();
Save(window, Path.Combine(directory, $"uploader-queue{suffix}.png"));
+ sample.ShowUpdate();
vm.IsSettingsOpen = true;
Save(window, Path.Combine(directory, $"uploader-settings{suffix}.png"));
vm.IsSettingsOpen = false;
diff --git a/src/Chronos.Uploader/Shell/UpdatesViewModel.cs b/src/Chronos.Uploader/Shell/UpdatesViewModel.cs
new file mode 100644
index 00000000..8a65b7b5
--- /dev/null
+++ b/src/Chronos.Uploader/Shell/UpdatesViewModel.cs
@@ -0,0 +1,157 @@
+using System.Windows.Input;
+using Chronos.Core.Diagnostics;
+using Chronos.Core.Localization;
+using Chronos.Core.Updates;
+using Chronos.Ui.Controls;
+using Chronos.Ui.Mvvm;
+using Chronos.Ui.Updates;
+using Chronos.Uploader.Infrastructure;
+using Chronos.Uploader.Text;
+
+namespace Chronos.Uploader.Shell;
+
+///
+/// The Updates row of the Uploader's settings panel (BRIEF §18, owner review 5): Check on start (opt-out), Check now,
+/// then Download, which fetches the single setup (the portable zip for a portable copy), verifies it against the
+/// release's SHA256SUMS and shows it in Explorer, and Show setup. The work is the desktop's .
+/// The start-up check is skipped when Chronos Desktop sits beside the Uploader: its own notice covers the same setup.
+///
+public sealed class UpdatesViewModel : LocalizedViewModel
+{
+ private readonly UpdateFlow _flow;
+ private readonly UploaderSettings _settings;
+ private readonly Action _saveSettings;
+ private UpdateState _shown;
+
+ public UpdatesViewModel(UpdateHost host, UploaderSettings settings, Action saveSettings)
+ {
+ _flow = new UpdateFlow(host);
+ _settings = settings;
+ _saveSettings = saveSettings;
+ _flow.Changed += RaiseState;
+ CancelCommand = new RelayCommand(_flow.CancelDownload, () => IsDownloading);
+ ShowSetupCommand = new RelayCommand(() =>
+ {
+ if (_flow.PackagePath is { } path) host.Reveal(path);
+ }, () => _flow.PackagePath is not null);
+ }
+
+ /// The start-up check found a newer release; the window offers it in a toast.
+ public event Action? Found;
+
+ public UpdateState State => _flow.State;
+
+ public bool CheckOnStart
+ {
+ get => _settings.CheckForUpdates;
+ set
+ {
+ if (_settings.CheckForUpdates == value) return;
+ _settings.CheckForUpdates = value;
+ _saveSettings();
+ Log.Info("settings", "Check for updates on start " + (value ? "on" : "off"));
+ OnPropertyChanged();
+ }
+ }
+
+ public ICommand CheckCommand => _flow.Check;
+ public ICommand DownloadCommand => _flow.Download;
+ public ICommand CancelCommand { get; }
+ public ICommand ShowSetupCommand { get; }
+
+ /// "Up to date", "Version 1.1.0 available", "Check failed", …; null before the first check.
+ public string? StatusText => _flow.State switch
+ {
+ UpdateState.Checking => Loc.L("Uploader.Updates.Checking"),
+ UpdateState.UpToDate => Loc.L("Uploader.Updates.UpToDate"),
+ UpdateState.Available when _flow.Release is { } r => Loc.L("Uploader.Updates.Available", UpdateCheck.Display(r.Version)),
+ UpdateState.Failed => Loc.L("Uploader.Updates.Failed"),
+ UpdateState.Downloading => Loc.L("Uploader.Updates.Downloading", _flow.Downloaded),
+ UpdateState.Downloaded when _flow.Release is { } r => Loc.L("Uploader.Updates.Ready", UpdateCheck.Display(r.Version)),
+ UpdateState.DownloadFailed => Loc.L("Uploader.Updates.DownloadFailed"),
+ UpdateState.NotVerified => Loc.L("Uploader.Updates.NotVerified"),
+ _ => null,
+ };
+
+ /// What screen readers announce: each new state, not each percent of a download.
+ public string? StatusAnnouncement => _flow.State == UpdateState.Downloading ? Loc.L("Uploader.Updates.InProgress") : StatusText;
+
+ /// What a state means and what to do next; null where the text says it all.
+ public string? StatusToolTip => _flow.State switch
+ {
+ UpdateState.UpToDate => Loc.L("Tooltips.Uploader.Updates.UpToDate"),
+ UpdateState.Available => Loc.L("Tooltips.Uploader.Updates.Available"),
+ UpdateState.Failed => Loc.L("Tooltips.Uploader.Updates.Failed"),
+ _ => null,
+ };
+
+ public StatusKind StatusKind => _flow.State switch
+ {
+ UpdateState.Checking or UpdateState.Downloading => StatusKind.Running,
+ UpdateState.UpToDate or UpdateState.Downloaded => StatusKind.Done,
+ UpdateState.Available => StatusKind.Warning,
+ _ => StatusKind.Error,
+ };
+
+ public bool HasStatus => StatusText is not null;
+
+ /// Download is offered: a newer release exists and no verified package is waiting (a failed download can be retried).
+ public bool IsDownloadOffered => _flow.IsDownloadOffered;
+
+ public bool IsDownloading => _flow.State == UpdateState.Downloading;
+
+ /// The verified setup or portable zip is in the temporary folder.
+ public bool IsReady => _flow.State == UpdateState.Downloaded;
+
+ /// The verified package; null until a download succeeded.
+ public string? PackagePath => _flow.PackagePath;
+
+ /// What Download does here: fetch and verify the setup or the portable zip (with its size), or open the release page.
+ public string DownloadToolTip => _flow.Package is { } package
+ ? Loc.L(_flow.IsPortable ? "Tooltips.Uploader.Updates.DownloadPortable" : "Tooltips.Uploader.Updates.Download", UploaderText.Bytes(package.Size, Loc.Culture))
+ : Loc.L("Tooltips.Uploader.Updates.DownloadPage");
+
+ public string ShowSetupToolTip => Loc.L(_flow.IsPortable ? "Tooltips.Uploader.Updates.ShowPortable" : "Tooltips.Uploader.Updates.ShowSetup");
+
+ /// The start-up check runs when the user left it on and Chronos Desktop is not installed beside the Uploader.
+ public static bool ChecksOnStart(bool enabled, bool desktopBeside) => enabled && !desktopBeside;
+
+ ///
+ /// The start-up check (never in a capture run): raises when a newer release exists. Skipped when
+ /// the user turned it off or Chronos Desktop is beside the Uploader.
+ ///
+ public async Task CheckOnStartAsync(bool desktopBeside)
+ {
+ if (!ChecksOnStart(CheckOnStart, desktopBeside))
+ {
+ Log.Info("update", desktopBeside ? "Start-up update check left to Chronos Desktop" : "Start-up update check off");
+ return;
+ }
+ if (await _flow.CheckOnStartAsync(enabled: true) is { } newer) Found?.Invoke(newer);
+ }
+
+ /// Sets a check result without the network (capture, tests).
+ public void SetResult(ReleaseInfo? release, bool failed = false) => _flow.SetResult(release, failed);
+
+ private void RaiseState()
+ {
+ // The flow reports each percent of a download too; State changes only with the state, so the view announces it once.
+ if (_shown != _flow.State)
+ {
+ _shown = _flow.State;
+ OnPropertyChanged(nameof(State));
+ }
+ OnPropertyChanged(nameof(StatusText));
+ OnPropertyChanged(nameof(StatusAnnouncement));
+ OnPropertyChanged(nameof(StatusToolTip));
+ OnPropertyChanged(nameof(StatusKind));
+ OnPropertyChanged(nameof(HasStatus));
+ OnPropertyChanged(nameof(IsDownloadOffered));
+ OnPropertyChanged(nameof(IsDownloading));
+ OnPropertyChanged(nameof(IsReady));
+ OnPropertyChanged(nameof(PackagePath));
+ OnPropertyChanged(nameof(DownloadToolTip));
+ OnPropertyChanged(nameof(ShowSetupToolTip));
+ CommandManager.InvalidateRequerySuggested();
+ }
+}
diff --git a/tests/Chronos.App.Tests/Uploader/UploaderUpdatesTests.cs b/tests/Chronos.App.Tests/Uploader/UploaderUpdatesTests.cs
new file mode 100644
index 00000000..fb4720b1
--- /dev/null
+++ b/tests/Chronos.App.Tests/Uploader/UploaderUpdatesTests.cs
@@ -0,0 +1,251 @@
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Security.Cryptography;
+using System.Text;
+using Chronos.Core.Localization;
+using Chronos.Core.Updates;
+using Chronos.Testing;
+using Chronos.Ui.Mvvm;
+using Chronos.Ui.Updates;
+using Chronos.Uploader.Infrastructure;
+using Chronos.Uploader.Shell;
+
+namespace Chronos.App.Tests.Uploader;
+
+///
+/// The Uploader's update check (owner review 5, #64): on by default, also for a 1.0 settings file; skipped on start when
+/// Chronos Desktop sits beside it while Check now still works; Check now reads the releases feed; Download verifies the
+/// single setup against SHA256SUMS and Show setup reveals it.
+///
+public sealed class UploaderUpdatesTests(TestContext context)
+{
+ private const string Repository = "https://gitea.example/o/r";
+ private const string SetupName = "Chronos-Setup-1.1.0.exe";
+ private static readonly byte[] Setup = Encoding.UTF8.GetBytes("the single setup of Chronos 1.1.0");
+
+ [Test]
+ public void CheckOnStartIsOnByDefaultAndA10SettingsFileKeepsIt()
+ {
+ Assert.True(new UploaderSettings().CheckForUpdates);
+
+ var folder = context.CreateTempDirectory();
+ var path = Path.Combine(folder, "uploader.json");
+ // An Uploader 1.0 settings file: no checkForUpdates key.
+ File.WriteAllText(path, """
+ {
+ "serverUrl": "https://nas.local:8443/",
+ "username": "alberto",
+ "bandwidthLimit": 50,
+ "minimizeToTray": true,
+ "deleteAfterUpload": false,
+ "target": "Sessions",
+ "watchFolders": [],
+ "theme": "Dark"
+ }
+ """);
+ var loaded = UploaderSettings.Load(path);
+ Assert.True(loaded.CheckForUpdates, "a 1.0 file loads with the check on");
+ Assert.Equal("alberto", loaded.Username);
+
+ loaded.CheckForUpdates = false;
+ loaded.Save(path);
+ Assert.Contains("\"checkForUpdates\": false", File.ReadAllText(path));
+ Assert.False(UploaderSettings.Load(path).CheckForUpdates, "the opt-out survives a restart");
+ }
+
+ [Test]
+ public void TheDesktopIsFoundBesideTheUploader()
+ {
+ var folder = context.CreateTempDirectory();
+ Assert.False(UploaderEnvironment.IsDesktopBeside(folder));
+ File.WriteAllText(Path.Combine(folder, UploaderEnvironment.DesktopExecutable), "desktop");
+ Assert.True(UploaderEnvironment.IsDesktopBeside(folder));
+ }
+
+ [Test]
+ public void TheStartUpCheckIsSkippedBesideTheDesktopWhileCheckNowStillWorks() => SingleThreadedContext.Run(async () =>
+ {
+ Assert.True(UpdatesViewModel.ChecksOnStart(enabled: true, desktopBeside: false));
+ Assert.False(UpdatesViewModel.ChecksOnStart(enabled: true, desktopBeside: true));
+ Assert.False(UpdatesViewModel.ChecksOnStart(enabled: false, desktopBeside: false));
+
+ var feed = new Feed().Release("v1.1.0");
+ using var vm = Notice(feed, out _);
+ ReleaseInfo? found = null;
+ vm.Found += r => found = r;
+
+ await vm.CheckOnStartAsync(desktopBeside: true);
+ Assert.Equal(0, feed.FeedRequests);
+ Assert.Equal(UpdateState.Unknown, vm.State);
+ Assert.Null(vm.StatusText);
+
+ await RunAsync(vm.CheckCommand);
+ Assert.Equal(1, feed.FeedRequests);
+ Assert.Equal(Loc.L("Uploader.Updates.Available", "1.1.0"), vm.StatusText);
+ Assert.Null(found, "Check now reports in the panel, not in a toast");
+ });
+
+ [Test]
+ public void TheStartUpCheckFollowsTheOptOutAndOffersANewerRelease() => SingleThreadedContext.Run(async () =>
+ {
+ var feed = new Feed().Release("v1.1.0");
+ var settings = new UploaderSettings { CheckForUpdates = false };
+ var saves = 0;
+ using var vm = new UpdatesViewModel(Host(feed, context.CreateTempDirectory(), []), settings, () => saves++);
+ ReleaseInfo? found = null;
+ vm.Found += r => found = r;
+
+ await vm.CheckOnStartAsync(desktopBeside: false);
+ Assert.Equal(0, feed.FeedRequests);
+
+ vm.CheckOnStart = true;
+ Assert.True(settings.CheckForUpdates);
+ Assert.Equal(1, saves);
+ await vm.CheckOnStartAsync(desktopBeside: false);
+ Assert.Equal(1, feed.FeedRequests);
+ Assert.Equal("v1.1.0", found?.Tag);
+ Assert.True(vm.IsDownloadOffered);
+ });
+
+ [Test]
+ public void CheckNowShowsUpToDateAvailableOrFailed() => SingleThreadedContext.Run(async () =>
+ {
+ var current = new Feed().Release("v1.0.0");
+ using (var vm = Notice(current, out _))
+ {
+ await RunAsync(vm.CheckCommand);
+ Assert.Equal(UpdateState.UpToDate, vm.State);
+ Assert.Equal(Loc.L("Uploader.Updates.UpToDate"), vm.StatusText);
+ Assert.Equal(Loc.L("Tooltips.Uploader.Updates.UpToDate"), vm.StatusToolTip);
+ Assert.False(vm.IsDownloadOffered);
+ }
+
+ var newer = new Feed().Release("v1.1.0");
+ using (var vm = Notice(newer, out _))
+ {
+ await RunAsync(vm.CheckCommand);
+ Assert.Equal(Loc.L("Uploader.Updates.Available", "1.1.0"), vm.StatusText);
+ Assert.Equal(Loc.L("Tooltips.Uploader.Updates.Available"), vm.StatusToolTip);
+ Assert.True(vm.IsDownloadOffered);
+ Assert.Contains("SHA-256", vm.DownloadToolTip);
+ }
+
+ foreach (var status in new[] { HttpStatusCode.NotFound, HttpStatusCode.InternalServerError })
+ {
+ var broken = new Feed { FeedStatus = status };
+ using var vm = Notice(broken, out _);
+ await RunAsync(vm.CheckCommand);
+ Assert.Equal(UpdateState.Failed, vm.State);
+ Assert.Equal(Loc.L("Uploader.Updates.Failed"), vm.StatusText);
+ Assert.Equal(Loc.L("Tooltips.Uploader.Updates.Failed"), vm.StatusToolTip);
+ }
+ });
+
+ [Test]
+ public void DownloadVerifiesTheSetupAndShowSetupRevealsIt() => SingleThreadedContext.Run(async () =>
+ {
+ var feed = new Feed().Release("v1.1.0");
+ using var vm = Notice(feed, out var revealed);
+ await RunAsync(vm.CheckCommand);
+ await RunAsync(vm.DownloadCommand);
+
+ Assert.Equal(UpdateState.Downloaded, vm.State);
+ Assert.True(vm.IsReady);
+ Assert.Equal(Loc.L("Uploader.Updates.Ready", "1.1.0"), vm.StatusText);
+ var path = Assert.NotNull(vm.PackagePath);
+ Assert.Equal(SetupName, Path.GetFileName(path));
+ Assert.SequenceEqual(Setup, File.ReadAllBytes(path));
+ Assert.SequenceEqual(new[] { path }, revealed);
+
+ Assert.True(vm.ShowSetupCommand.CanExecute(null));
+ vm.ShowSetupCommand.Execute(null);
+ Assert.SequenceEqual(new[] { path, path }, revealed);
+ });
+
+ [Test]
+ public void ASetupThatDoesNotMatchItsChecksumIsRefused() => SingleThreadedContext.Run(async () =>
+ {
+ var feed = new Feed { WrongChecksum = true }.Release("v1.1.0");
+ using var vm = Notice(feed, out var revealed);
+ await RunAsync(vm.CheckCommand);
+ await RunAsync(vm.DownloadCommand);
+
+ Assert.Equal(UpdateState.NotVerified, vm.State);
+ Assert.Equal(Loc.L("Uploader.Updates.NotVerified"), vm.StatusText);
+ Assert.Null(vm.PackagePath);
+ Assert.Empty(revealed);
+ Assert.False(vm.ShowSetupCommand.CanExecute(null));
+ Assert.True(vm.IsDownloadOffered, "the download can be tried again");
+ });
+
+ [Test]
+ public void TheCaptureNoticeNeverTouchesTheNetwork() => SingleThreadedContext.Run(async () =>
+ {
+ using var vm = new UpdatesViewModel(UploaderUpdates.Offline("1.0.0"), new UploaderSettings(), () => { });
+ await vm.CheckOnStartAsync(desktopBeside: false);
+ await RunAsync(vm.CheckCommand);
+ Assert.Equal(UpdateState.Unknown, vm.State);
+ });
+
+ private UpdatesViewModel Notice(Feed feed, out List revealed)
+ {
+ revealed = [];
+ return new UpdatesViewModel(Host(feed, context.CreateTempDirectory(), revealed), new UploaderSettings(), () => { });
+ }
+
+ private static UpdateHost Host(Feed feed, string downloadRoot, List revealed)
+ {
+ var http = new HttpClient(feed, disposeHandler: false);
+ return UploaderUpdates.Host(http, http, Repository, "1.0.0", portable: false, downloadRoot, _ => { }, revealed.Add);
+ }
+
+ private static async Task RunAsync(System.Windows.Input.ICommand command)
+ {
+ var async = (AsyncRelayCommand)command;
+ async.Execute(null);
+ for (var i = 0; i < 500 && async.IsRunning; i++) await Task.Delay(10);
+ Assert.False(async.IsRunning, "the command did not finish");
+ }
+
+ /// The releases API, the setup and its SHA256SUMS, served from memory.
+ private sealed class Feed : HttpMessageHandler
+ {
+ private string _json = "[]";
+ private string _sums = string.Empty;
+ private string _tag = string.Empty;
+
+ public HttpStatusCode FeedStatus { get; init; } = HttpStatusCode.OK;
+ public bool WrongChecksum { get; init; }
+ public int FeedRequests { get; private set; }
+
+ public Feed Release(string tag)
+ {
+ _tag = tag;
+ var hash = WrongChecksum ? new string('0', 64) : Convert.ToHexStringLower(SHA256.HashData(Setup));
+ _sums = $"{hash} {SetupName}\n";
+ _json = $$"""
+ [{"tag_name":"{{tag}}","draft":false,"prerelease":false,"html_url":"{{Repository}}/releases/tag/{{tag}}",
+ "assets":[{"name":"{{SetupName}}","size":{{Setup.Length}},"browser_download_url":"x"},
+ {"name":"SHA256SUMS","size":{{_sums.Length}},"browser_download_url":"x"}]}]
+ """;
+ return this;
+ }
+
+ protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ var path = request.RequestUri!.AbsolutePath;
+ if (path == "/api/v1/repos/o/r/releases")
+ {
+ FeedRequests++;
+ return Answer(FeedStatus, Encoding.UTF8.GetBytes(_json));
+ }
+ if (path == $"/o/r/releases/download/{_tag}/SHA256SUMS") return Answer(HttpStatusCode.OK, Encoding.UTF8.GetBytes(_sums));
+ if (path == $"/o/r/releases/download/{_tag}/{SetupName}") return Answer(HttpStatusCode.OK, Setup);
+ return Answer(HttpStatusCode.NotFound, []);
+ }
+
+ private static Task Answer(HttpStatusCode status, byte[] body) =>
+ Task.FromResult(new HttpResponseMessage(status) { Content = new ByteArrayContent(body) });
+ }
+}