Public Access
ADR 0014 gave the phone a nightly and ADR 0013 rule 3 gave the desktop none, so the two heads had different answers to the same question — how does somebody try what is on main? — for no reason except the order the work happened in. This is the desktop's answer: CI publishes a build from main on every push, and it installs beside the release one rather than over it. The phone gets its separation from the platform. Android refuses an update signed by a different key, so its two channels cannot replace one another whatever anybody does. Nothing refuses anything here: Velopack applies what its feed serves and verifies no signature. So all of it is construction, and there are four separations because each closes a different door. A pack id each, so the two install in different directories and neither feed's package can be applied to the other's install. A Velopack channel each — win and win-nightly — so neither build ever reads the other's release index; the name reaches the wire as releases.win-nightly.json, which is why the constant in VelopackUpdateChannel and the argument in ci.yml have to agree or the channel answers nothing forever with no error. A prerelease flag, so the release channel cannot see the nightly even by accident. And a profile directory each, which is the one that is easy to skip and would hurt most: the cache schema is migrated on every launch, before unlock, so a shared profile means a nightly quietly upgrading a database the release build then opens. Both are installed at once by design, so that is an ordinary Tuesday rather than a corner case. The prerelease flag turns out to be load-bearing across heads as well. The phone's release channel reads releases/latest, which skips prereleases — so a desktop nightly published as a stable release would become the newest release in this repository and every phone on the release channel would start failing its check against a release carrying no Android manifest. Which build this is arrives as assembly metadata, the same mechanism and the same reasoning as the Android head: the updater needs the string rather than a branch, and a value baked into the assembly is one a crash report can be asked for. Three things read it — the feed, the prerelease flag, and the profile — and one more shows it: the titlebar says DodoSSH Nightly. Everything else that distinguishes the two is somewhere nobody is looking while typing a passphrase into one of them. The version needed a floor and it is applied to the whole build rather than to the packaging. MinVer answers 0.0.0-alpha.0.N until the first v* tag and vpk refuses anything below 0.0.1, so the job lifts the patch digit and keeps the height — through MinVerVersionOverride, so the assemblies carry the same number the installer does. Packing a version the assembly disagreed with would put one string on the preferences screen and another in the feed, which is the screen somebody reads when asked which nightly they are on. Two things found by running it rather than reading it. -t:MinVer needs a restore first, because the target arrives with the package and MSB4057 on a clean checkout reads like a typo in the workflow rather than a missing restore; the release script had the same gap and now restores before it reads. And vpk rejects an empty --packVersion loudly, which is how a broken version handoff announces itself rather than shipping a package called 1.0.0. Rule 3 is untouched. The release channel still has no job, no token and no runner, and the two channels cannot see each other. What a nightly costs is written where somebody reads it before installing one: whoever can write a release here can put a build on every nightly machine, which is fine for a build being tried and is not fine for a build holding somebody's infrastructure credentials. Verified by running the job's own steps against a clone in a Linux container: DodoSSH.Desktop.Nightly-win-nightly-Setup.exe, and an index naming pack id DodoSSH.Desktop.Nightly at 0.0.1-alpha.0.144. The upload itself is the one step not exercised — it needs a real forge and a write token, and check 16.10 is what walks the half no runner can.
189 lines
8.0 KiB
C#
189 lines
8.0 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Input.Platform;
|
|
using Avalonia.Markup.Xaml;
|
|
using DodoSSH.Client.App.Platform;
|
|
using DodoSSH.Client.App.Views;
|
|
using DodoSSH.Client.Auth;
|
|
using DodoSSH.Client.Session;
|
|
using DodoSSH.Client.Shell.Terminal;
|
|
using DodoSSH.Client.Shell.ViewModels;
|
|
using DodoSSH.Client.Ssh;
|
|
using DodoSSH.Client.Storage;
|
|
using DodoSSH.Client.Terminal;
|
|
|
|
namespace DodoSSH.Client.App;
|
|
|
|
/// <summary>
|
|
/// The Avalonia application.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Named <c>DodoSshApp</c> rather than the conventional <c>App</c> only because the assembly's root
|
|
/// namespace already ends in <c>App</c>, and a type whose name matches its namespace forces every
|
|
/// ambiguous reference to be fully qualified.
|
|
/// </remarks>
|
|
internal sealed partial class DodoSshApp : Application
|
|
{
|
|
/// <inheritdoc />
|
|
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
|
|
|
/// <inheritdoc />
|
|
public override void OnFrameworkInitializationCompleted()
|
|
{
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
Compose(desktop);
|
|
}
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
}
|
|
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Composed by hand rather than through a container. The graph is a handful of objects deep and an
|
|
/// indirection to read through would buy nothing at this size.
|
|
/// </para>
|
|
/// <para>
|
|
/// Everything disposable is a local captured by the closures below rather than a field, because an
|
|
/// Avalonia <c>Application</c> has no disposal hook of its own and a type that owned them would have
|
|
/// nowhere honest to release them.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <summary>
|
|
/// Puts one line of text on the system clipboard.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The clipboard is reached through the window, and at composition time there is no window yet — hence
|
|
/// a closure that looks it up on each call rather than a reference captured now. A machine with no
|
|
/// clipboard falls through silently here; the view model is the one that decides what to say, and it
|
|
/// distinguishes "no clipboard on this machine" from "copied" because they are different answers.
|
|
/// <para>
|
|
/// A delegate rather than handing the view model an <c>IClipboard</c>, so that nothing in the view
|
|
/// models needs a visual and every test that drives them stays window-free.
|
|
/// </para>
|
|
/// </remarks>
|
|
private static Func<string, Task> ClipboardWriter(IClassicDesktopStyleApplicationLifetime desktop) =>
|
|
async text =>
|
|
{
|
|
if (TopLevel.GetTopLevel(desktop.MainWindow) is { Clipboard: { } clipboard })
|
|
{
|
|
await clipboard.SetTextAsync(text).ConfigureAwait(false);
|
|
}
|
|
};
|
|
|
|
/// <summary>The terminal workspace, with its loopback listener already up.</summary>
|
|
/// <remarks>
|
|
/// Extracted so that constructing it and starting it cannot drift apart: the data plane's socket has to
|
|
/// be listening before the renderer attaches, and a workspace handed out un-started is one whose first
|
|
/// connect fails for a reason nothing on screen would explain.
|
|
/// </remarks>
|
|
private static TerminalWorkspace StartedWorkspace(SshNetConnectionFactory connections)
|
|
{
|
|
var workspace = new TerminalWorkspace(
|
|
new AvaloniaTerminalAssetProvider(),
|
|
connections,
|
|
TimeProvider.System);
|
|
|
|
workspace.Start();
|
|
|
|
return workspace;
|
|
}
|
|
|
|
private static void Compose(IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
// ForChannel rather than Default, so a nightly keeps its cache, outbox and device key somewhere
|
|
// the release build never opens. See ClientPaths.ForChannel for why sharing them is the failure
|
|
// worth spending a directory on.
|
|
var paths = ClientPaths.ForChannel(DesktopChannel.Name);
|
|
var caches = ClientCacheFactory.ForFile(paths.CacheFile);
|
|
|
|
// Known hosts live in the vault, so trust survives a restart and follows the user to every device.
|
|
// Composed here, once, because the connection factory below needs it now and outlives every unlock;
|
|
// the vault behind it is attached and detached as one is opened and locked. See VaultKnownHostStore
|
|
// for why the handshake is answered from a snapshot rather than by reading the vault per lookup.
|
|
var knownHosts = new VaultKnownHostStore();
|
|
|
|
// One factory for both kinds of connection. Shells and file transfers start with the same handshake
|
|
// and the same host key decision, and composing two would mean two snapshots of the pins.
|
|
var connections = new SshNetConnectionFactory(knownHosts);
|
|
|
|
var workspace = StartedWorkspace(connections);
|
|
|
|
var browser = new SystemBrowserLauncher();
|
|
|
|
// Both chosen once, here, because each is a property of the machine rather than of any session. A
|
|
// computer with a usable TPM gets the store that keeps a device key behind a Windows consent prompt;
|
|
// anything else gets one that reports itself unavailable, so unlock keeps asking for the passphrase
|
|
// (ADR 0007). The update channel answers the same shape of question about how this copy was
|
|
// installed, and a build run from a checkout likewise gets one that says so. See ADR 0013.
|
|
var deviceKeys = DesktopDeviceKeyStores.ForThisMachine(paths);
|
|
var updates = UpdateChannels.ForThisMachine();
|
|
|
|
var viewModel = new MainWindowViewModel(
|
|
paths,
|
|
caches,
|
|
workspace,
|
|
knownHosts,
|
|
deviceKeys,
|
|
async (url, cancellationToken) => await ServerConnection
|
|
.SignInAsync(url, browser, TimeProvider.System, cancellationToken)
|
|
.ConfigureAwait(false),
|
|
TimeProvider.System,
|
|
connections,
|
|
passphraseProfile: null,
|
|
|
|
// The other half of signing in: a refresh grant, no browser, and nobody present. It is what
|
|
// makes a launch after the first one arrive online rather than merely enrolled.
|
|
resume: async (url, refreshToken, cancellationToken) => await ServerConnection
|
|
.ResumeAsync(url, refreshToken, TimeProvider.System, cancellationToken)
|
|
.ConfigureAwait(false),
|
|
|
|
copyToClipboard: ClipboardWriter(desktop),
|
|
updates: updates);
|
|
|
|
desktop.MainWindow = new MainWindow { DataContext = viewModel };
|
|
|
|
// Started rather than awaited: the framework's initialisation must not block on a schema
|
|
// migration. The view model shows its own progress and handles its own failures, which is why
|
|
// discarding the task here is safe rather than merely convenient.
|
|
_ = viewModel.StartAsync(CancellationToken.None);
|
|
|
|
WireShutdown(desktop, viewModel, workspace, caches);
|
|
}
|
|
|
|
/// <remarks>
|
|
/// Shutdown is deferred rather than blocked on. Sessions hold SSH connections and a listening socket, and
|
|
/// blocking the UI thread on their disposal is how an application comes to take several seconds to close —
|
|
/// or deadlocks, if any of that disposal needs the UI thread.
|
|
/// </remarks>
|
|
private static void WireShutdown(
|
|
IClassicDesktopStyleApplicationLifetime desktop,
|
|
MainWindowViewModel viewModel,
|
|
TerminalWorkspace workspace,
|
|
ClientCacheFactory caches)
|
|
{
|
|
var shuttingDown = false;
|
|
|
|
desktop.ShutdownRequested += async (_, e) =>
|
|
{
|
|
if (shuttingDown)
|
|
{
|
|
return;
|
|
}
|
|
|
|
shuttingDown = true;
|
|
e.Cancel = true;
|
|
|
|
// The view model first: it holds the vault session, and disposing that is what zeroes the
|
|
// identity keys, the vault keys and the cache key.
|
|
await viewModel.DisposeAsync().ConfigureAwait(true);
|
|
await workspace.DisposeAsync().ConfigureAwait(true);
|
|
|
|
caches.Dispose();
|
|
|
|
desktop.Shutdown();
|
|
};
|
|
}
|
|
}
|