fix(app): resumable, cancellable update download; portable copies get the portable zip

- UpdateFlow owns the update notice (check, download, cancel) as a plain class;
  AboutViewModel only maps it to text and commands.
- A portable copy downloads and verifies Titano-win-x64-portable-<v>.zip instead
  of the setup; a release without the package or SHA256SUMS opens its page.
- The download fails after 60 s without data instead of after 30 minutes,
  keeps its .part file and resumes it with a range request; Cancel stops it.
- Older release folders under %TEMP%\Titano\updates are removed after a
  verified download; an unexpected exception never leaves "Downloading".
- Tooltips show the package size; stale machine translations of the three
  rewritten tooltips are removed so they fall back to English.

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-03 10:00:54 +00:00
1 parent aac2539276
commit ffa05d9f69
36 files changed
+828 -298

No files matched your search

+7 -4
View File
@@ -55,11 +55,14 @@
<ui:StatusGlyph Kind="{Binding UpdateKind}" Text="{Binding UpdateText}" FontSize="13" VerticalAlignment="Center"
Visibility="{Binding HasUpdateText, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.Download}"
Command="{Binding DownloadCommand}" ToolTip="{l:Loc Tooltips.About.Download}"
Command="{Binding DownloadCommand}" ToolTip="{Binding DownloadToolTip}"
Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.ShowSetup}"
Command="{Binding ShowSetupCommand}" ToolTip="{l:Loc Tooltips.About.ShowSetup}"
Visibility="{Binding IsSetupReady, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.Cancel}"
Command="{Binding CancelDownloadCommand}" ToolTip="{l:Loc Tooltips.About.CancelDownload}"
Visibility="{Binding IsDownloading, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.ShowFile}"
Command="{Binding ShowPackageCommand}" ToolTip="{Binding ShowPackageToolTip}"
Visibility="{Binding IsPackageReady, Converter={StaticResource BoolToVisibility}}" />
</StackPanel>
</Grid>
+43 -113
View File
@@ -1,12 +1,10 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Input;
using Titano.App.About;
using Titano.App.Infrastructure;
using Titano.App.Shell;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Ui.Controls;
using Titano.Ui.Mvvm;
@@ -15,27 +13,26 @@ namespace Titano.App.Sections;
/// <summary>
/// About (BRIEF §12.9): version and build, licence link, third-party notice (none), translation notice,
/// diagnostics bundle and the update check against the public releases repository (BRIEF §18). Download fetches the
/// setup and verifies it against the release's SHA256SUMS, then shows it in Explorer: BRIEF §8.6 does not allow Titano
/// to start an installer, so the user runs it.
/// diagnostics bundle and the update notice of <see cref="UpdateFlow"/> (BRIEF §18), which Settings › Updates shows too.
/// </summary>
public sealed class AboutViewModel : SectionViewModel
{
private ReleaseInfo? _release;
private UpdateState _state = UpdateState.Unknown;
private double _downloaded;
private string? _setupPath;
private readonly UpdateFlow _update;
public AboutViewModel(ShellViewModel shell)
: base(SectionKey.About, "Icon.About")
{
Shell = shell;
CheckCommand = new AsyncRelayCommand(() => CheckAsync(notify: false), () => _state is not (UpdateState.Checking or UpdateState.Downloading));
DownloadCommand = new AsyncRelayCommand(DownloadAsync, () => _release is not null && _state != UpdateState.Downloading);
ShowSetupCommand = new RelayCommand(() =>
var environment = shell.Services.Environment;
_update = new UpdateFlow(new UpdateHost(UpdateCheck.RunningVersion(Version), environment.IsCapture, environment.IsPortable,
ct => Shell.Services.CheckForUpdateAsync(ct), (release, progress, ct) => Shell.Services.DownloadUpdateAsync(release, progress, ct),
ShellActions.OpenUrl, ShellActions.Reveal));
_update.Changed += RaiseUpdate;
ShowPackageCommand = new RelayCommand(() =>
{
if (_setupPath is { } path) ShellActions.Reveal(path);
}, () => _setupPath is not null);
if (_update.PackagePath is { } path) ShellActions.Reveal(path);
}, () => _update.PackagePath is not null);
CancelDownloadCommand = new RelayCommand(_update.CancelDownload, () => IsDownloading);
OpenReleasesCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Releases));
OpenLicenceCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Licence));
ReviewTranslationCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Issues));
@@ -43,19 +40,6 @@ public sealed class AboutViewModel : SectionViewModel
DiagnosticsCommand = new AsyncRelayCommand(DiagnosticsAsync);
}
private enum UpdateState
{
Unknown,
Checking,
UpToDate,
Available,
Failed,
Downloading,
Downloaded,
DownloadFailed,
NotVerified,
}
public ShellViewModel Shell { get; }
public string Version => AppServices.VersionText;
@@ -73,9 +57,10 @@ public sealed class AboutViewModel : SectionViewModel
/// <summary>Every language but English is machine-translated and open to review (BRIEF §16).</summary>
public bool IsTranslated => !Loc.Culture.TwoLetterISOLanguageName.Equals("en", StringComparison.OrdinalIgnoreCase);
public ICommand CheckCommand { get; }
public ICommand DownloadCommand { get; }
public ICommand ShowSetupCommand { get; }
public ICommand CheckCommand => _update.Check;
public ICommand DownloadCommand => _update.Download;
public ICommand ShowPackageCommand { get; }
public ICommand CancelDownloadCommand { get; }
public ICommand OpenReleasesCommand { get; }
public ICommand OpenLicenceCommand { get; }
public ICommand ReviewTranslationCommand { get; }
@@ -83,20 +68,20 @@ public sealed class AboutViewModel : SectionViewModel
public ICommand DiagnosticsCommand { get; }
/// <summary>"Up to date", "Titano 0.2.0 available", …; null before the first check.</summary>
public string? UpdateText => _state switch
public string? UpdateText => _update.State switch
{
UpdateState.Checking => Loc.L("About.Update.Checking"),
UpdateState.UpToDate => Loc.L("About.Update.Current"),
UpdateState.Available when _release is { } r => Loc.L("About.Update.Available", UpdateCheck.Display(r.Version)),
UpdateState.Available when _update.Release is { } r => Loc.L("About.Update.Available", UpdateCheck.Display(r.Version)),
UpdateState.Failed => Loc.L("About.Update.Failed"),
UpdateState.Downloading => Loc.L("About.Update.Downloading", _downloaded),
UpdateState.Downloaded when _release is { } r => Loc.L("About.Update.Ready", UpdateCheck.Display(r.Version)),
UpdateState.Downloading => Loc.L("About.Update.Downloading", _update.Downloaded),
UpdateState.Downloaded when _update.Release is { } r => Loc.L("About.Update.Ready", UpdateCheck.Display(r.Version)),
UpdateState.DownloadFailed => Loc.L("About.Update.DownloadFailed"),
UpdateState.NotVerified => Loc.L("About.Update.NotVerified"),
_ => null,
};
public StatusKind UpdateKind => _state switch
public StatusKind UpdateKind => _update.State switch
{
UpdateState.Checking or UpdateState.Downloading => StatusKind.Running,
UpdateState.UpToDate or UpdateState.Downloaded => StatusKind.Done,
@@ -106,89 +91,32 @@ public sealed class AboutViewModel : SectionViewModel
public bool HasUpdateText => UpdateText is not null;
/// <summary>Download is offered: a newer release exists and no verified setup is waiting (a failed download can be retried).</summary>
public bool IsUpdateAvailable => _state is UpdateState.Available or UpdateState.DownloadFailed or UpdateState.NotVerified;
/// <summary>Download is offered: a newer release exists and no verified package is waiting (a failed download can be retried).</summary>
public bool IsUpdateAvailable => _update.IsDownloadOffered;
/// <summary>The verified setup is in the temporary folder.</summary>
public bool IsSetupReady => _state == UpdateState.Downloaded;
/// <summary>The verified setup or portable zip is in the temporary folder.</summary>
public bool IsPackageReady => _update.State == UpdateState.Downloaded;
/// <summary>Starts the update check on start when allowed (opt-out, BRIEF §18).</summary>
public void Attach()
{
if (Shell.Services.Settings.CheckForUpdates && !Shell.Services.Environment.IsCapture) _ = CheckAsync(notify: true);
}
public bool IsDownloading => _update.State == UpdateState.Downloading;
/// <summary>What Download does here: fetch and verify the setup or the portable zip (with its size), or open the release page.</summary>
public string DownloadToolTip => _update.Package is { } package
? Loc.L(_update.IsPortable ? "Tooltips.About.DownloadPortable" : "Tooltips.About.Download", Formatting.Bytes(package.Size))
: Loc.L("Tooltips.About.DownloadPage");
public string ShowPackageToolTip => Loc.L(_update.IsPortable ? "Tooltips.About.ShowPortable" : "Tooltips.About.ShowSetup");
/// <summary>Starts the update check on start when allowed (opt-out, BRIEF §18); never in a capture run.</summary>
public void Attach() => _ = NotifyAsync();
/// <summary>Sets a result without the network (capture, tests).</summary>
internal void SetResult(ReleaseInfo? release, bool failed = false)
{
_release = release is not null && UpdateCheck.IsNewer(release, UpdateCheck.RunningVersion(Version)) ? release : null;
_state = failed ? UpdateState.Failed : _release is null ? UpdateState.UpToDate : UpdateState.Available;
_setupPath = null;
RaiseUpdate();
}
internal void SetResult(ReleaseInfo? release, bool failed = false) => _update.SetResult(release, failed);
private async Task CheckAsync(bool notify)
private async Task NotifyAsync()
{
_state = UpdateState.Checking;
RaiseUpdate();
try
{
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var release = await Shell.Services.CheckForUpdateAsync(timeout.Token);
SetResult(release);
if (notify && _release is { } newer)
{
Shell.Notify(Loc.L("About.Update.Available", UpdateCheck.Display(newer.Version)), actionText: Loc.L("About.Update.Download"),
actionToolTip: Loc.L("Tooltips.About.Download"), action: () => DownloadCommand.Execute(null));
}
}
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException or IOException)
{
Log.Info("update", "Update check failed: " + ex.Message);
SetResult(null, failed: true);
}
}
/// <summary>
/// Downloads and verifies the setup, then shows it in Explorer. A release without a setup or SHA256SUMS only opens
/// the release page; a capture run never touches the network.
/// </summary>
private async Task DownloadAsync()
{
if (_release is not { } release || Shell.Services.Environment.IsCapture) return;
if (!UpdateDownload.CanDownload(release))
{
ShellActions.OpenUrl(release.PageUrl);
return;
}
_state = UpdateState.Downloading;
_downloaded = 0;
RaiseUpdate();
var progress = new Progress<double>(fraction =>
{
if (_state != UpdateState.Downloading || fraction - _downloaded < 0.01) return;
_downloaded = fraction;
OnPropertyChanged(nameof(UpdateText));
});
try
{
using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(30));
_setupPath = await Shell.Services.DownloadUpdateAsync(release, progress, timeout.Token);
_state = UpdateState.Downloaded;
Log.Info("update", $"Setup of {release.Tag} downloaded and verified: {_setupPath}");
ShellActions.Reveal(_setupPath);
}
catch (UpdateVerificationException ex)
{
Log.Warning("update", "Update download refused: " + ex.Message);
_state = UpdateState.NotVerified;
}
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException or IOException or UnauthorizedAccessException)
{
Log.Warning("update", "Update download failed: " + ex.Message);
_state = UpdateState.DownloadFailed;
}
RaiseUpdate();
if (await _update.CheckOnStartAsync(Shell.Services.Settings.CheckForUpdates) is not { } newer) return;
Shell.Notify(Loc.L("About.Update.Available", UpdateCheck.Display(newer.Version)), actionText: Loc.L("About.Update.Download"),
actionToolTip: DownloadToolTip, action: () => DownloadCommand.Execute(null));
}
private async Task DiagnosticsAsync()
@@ -212,7 +140,9 @@ public sealed class AboutViewModel : SectionViewModel
OnPropertyChanged(nameof(UpdateKind));
OnPropertyChanged(nameof(HasUpdateText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(IsSetupReady));
OnPropertyChanged(nameof(IsPackageReady));
OnPropertyChanged(nameof(IsDownloading));
OnPropertyChanged(nameof(DownloadToolTip));
CommandManager.InvalidateRequerySuggested();
}
}
+6 -3
View File
@@ -291,12 +291,15 @@
<Button Content="{l:Loc About.Update.Check}" Command="{Binding Shell.About.CheckCommand}" ToolTip="{l:Loc Tooltips.About.Check}" />
<ui:StatusGlyph Kind="{Binding Shell.About.UpdateKind}" Text="{Binding Shell.About.UpdateText}" FontSize="13" VerticalAlignment="Center" Margin="12,0,0,0"
Visibility="{Binding Shell.About.HasUpdateText, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.Download}" Command="{Binding Shell.About.DownloadCommand}" ToolTip="{l:Loc Tooltips.About.Download}"
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.Download}" Command="{Binding Shell.About.DownloadCommand}" ToolTip="{Binding Shell.About.DownloadToolTip}"
VerticalAlignment="Center" Margin="12,0,0,0" FontSize="13"
Visibility="{Binding Shell.About.IsUpdateAvailable, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.ShowSetup}" Command="{Binding Shell.About.ShowSetupCommand}" ToolTip="{l:Loc Tooltips.About.ShowSetup}"
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.Cancel}" Command="{Binding Shell.About.CancelDownloadCommand}" ToolTip="{l:Loc Tooltips.About.CancelDownload}"
VerticalAlignment="Center" Margin="12,0,0,0" FontSize="13"
Visibility="{Binding Shell.About.IsSetupReady, Converter={StaticResource BoolToVisibility}}" />
Visibility="{Binding Shell.About.IsDownloading, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.ShowFile}" Command="{Binding Shell.About.ShowPackageCommand}" ToolTip="{Binding Shell.About.ShowPackageToolTip}"
VerticalAlignment="Center" Margin="12,0,0,0" FontSize="13"
Visibility="{Binding Shell.About.IsPackageReady, Converter={StaticResource BoolToVisibility}}" />
</WrapPanel>
</HeaderedContentControl>
</StackPanel>