Files
frameledger/src/FrameLedger.App/Update/UpdateHostedService.cs
T
poli0981andClaude Opus 5 1776a22907 feat(app): Velopack, the updater with FR-12 as its shape, release.yml, and one VERSION source (P4 PR-5) (#174)
* feat(app): Velopack, the updater with FR-12 as its shape, release.yml, and one VERSION source (P4 PR-5)

The updater of 11_UPDATER behind an IUpdateClient port (VelopackUpdateClient over Velopack 1.2.0's
GitHub source; stable = releases GitHub does not mark pre-release, beta adds them): the startup silent
check 5 s after start for an installed copy with update.auto_check on, Help > Check for updates with
the dialogs and the six error rows, the background download (a checksum failure retried once), and the
apply -- refused while any session runs, Deferred until the last SessionCompleted, then Shutdown to the
Agent, the connection's relaunch held, the pipe watched until it drops, WaitExitThenApplyUpdates, the
host ended. Program.Main runs VelopackApp first; the uninstall hook stops the Agent, unregisters the
layer, removes the logon task and asks about the data folder.

The package id is FrameLedger.App, not FrameLedger: Velopack installs into and deletes
%LOCALAPPDATA%\<packId>, which with the documented id is the data folder holding ledger.db.

VERSION at the root feeds Directory.Build.props and the native CMake project; versioninfo-check
compares every binary against it. release.yml gates the tag against VERSION and CHANGELOG
(tools/release-notes.ps1), substitutes {{RELEASE_DATE}}, runs the identical gate, publishes, asserts
the published tree, packs, checksums and releases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(app): the private constant's name, Velopack's copyright as its package states it, and the measured pack

- UpdateService: _idleState (IDE1006, the repository's private-field rule; dotnet format caught it).
- legal/licenses/velopack-MIT.txt and THIRD_PARTY_NOTICES: the copyright line is the package's own
  <copyright> field ("Velopack Ltd."), not a name written from memory.
- 12_BUILD / 13_CI_CD / CHANGELOG: vpk pack 1.2.0 run by hand over the published tree -- Setup 104 MB,
  VelopackApp.Run() verified in Program.Main.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:56:55 +07:00

52 lines
2.1 KiB
C#

using FrameLedger.App.Services;
using FrameLedger.Infrastructure.Startup;
using Microsoft.Extensions.Hosting;
using Serilog;
namespace FrameLedger.App.Update;
/// <summary>
/// The startup leg of <c>11_UPDATER</c> §Flow: the silent check 5 s after the host is up (the spec's "5 s after UI
/// idle", measured from start because the shell shows synchronously inside it), and — on the first run after an
/// update — the logon task's action path re-validated, because the updater rewrote the install directory
/// (<c>LogonTaskState.Stale</c> is the signal; <c>--install-task</c> the repair, this user's own task).
/// </summary>
internal sealed class UpdateHostedService(UpdateService updates, IMaintenanceState maintenance, IAgentTool tool) : BackgroundService
{
private static readonly TimeSpan _startupDelay = TimeSpan.FromSeconds(5);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
if (UpdateRestart.Detected)
{
await RepairTaskAsync(stoppingToken).ConfigureAwait(false);
}
await Task.Delay(_startupDelay, stoppingToken).ConfigureAwait(false);
await updates.CheckSilentlyAsync(stoppingToken).ConfigureAwait(false);
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Log.Warning(ex, "update: the startup check faulted");
}
}
private async Task RepairTaskAsync(CancellationToken ct)
{
MaintenanceSnapshot snapshot = await maintenance.ReadAsync(ct).ConfigureAwait(false);
if (snapshot.Task != LogonTaskState.Stale)
{
Log.Information("update: restarted after an update; the logon task is {State}", snapshot.Task);
return;
}
AgentToolResult result = await tool.RunAsync("--install-task", ct).ConfigureAwait(false);
Log.Information("update: restarted after an update; the logon task was stale and --install-task exited {Exit}", result.ExitCode);
}
}