mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
3039bebc6c
The single HostStatusText/JoinStatusText line gave no sense of where the user was in the flow. Replaced with a step list: - StartupStep model (INotifyPropertyChanged) tracks Title, State (Pending/Active/Done/Failed), Detail, optional Progress 0..1 - ItemsControl + DataTemplate in App.xaml renders each step as a status bullet (empty ring -> filled brand -> green check -> red X), with conditional detail line + restyled mini progress bar - StartupFlow.NewHostFlow / NewJoinFlow build the canonical 5-step host and 2-step join lists; host flow swaps the tunnel step label for LocalNetwork mode - OnHostStart / OnJoinApply advance steps via StartStep/CompleteStep/ FailStep helpers and route progress callbacks to UpdateStepProgress so each download phase has its own bar - Errors mark the active step Failed with the message inline, leaving the rest of the list visible so the user sees where it broke
90 lines
3.3 KiB
C#
90 lines
3.3 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace DorkNet.Launcher.Backend;
|
|
|
|
/// <summary>A single visible step in the host/join startup flow. The
|
|
/// XAML <c>ItemsControl</c> binds to a collection of these and the
|
|
/// DataTemplate switches presentation off <see cref="State"/>.
|
|
///
|
|
/// <para>This is a tiny INotifyPropertyChanged DTO on purpose — no MVVM
|
|
/// framework, no commands, no view-model layer. Code-behind owns the
|
|
/// collection and mutates fields as the flow progresses.</para></summary>
|
|
public sealed class StartupStep : INotifyPropertyChanged
|
|
{
|
|
public StartupStep(string title) { Title = title; }
|
|
|
|
public string Title { get; }
|
|
|
|
private StepState _state = StepState.Pending;
|
|
public StepState State
|
|
{
|
|
get => _state;
|
|
set { if (_state == value) return; _state = value; OnChanged(); OnChanged(nameof(IsActive)); }
|
|
}
|
|
|
|
private string _detail = "";
|
|
public string Detail
|
|
{
|
|
get => _detail;
|
|
set { if (_detail == value) return; _detail = value; OnChanged(); OnChanged(nameof(HasDetail)); }
|
|
}
|
|
|
|
/// <summary>0..1 progress fraction, or null for "no progress bar"
|
|
/// (e.g. an indeterminate phase like "starting server"). The
|
|
/// DataTemplate hides the bar when null.</summary>
|
|
private double? _progress;
|
|
public double? Progress
|
|
{
|
|
get => _progress;
|
|
set { if (_progress == value) return; _progress = value; OnChanged(); OnChanged(nameof(HasProgress)); OnChanged(nameof(ProgressPercent)); }
|
|
}
|
|
|
|
public bool HasDetail => !string.IsNullOrEmpty(_detail);
|
|
public bool HasProgress => _progress.HasValue;
|
|
public bool IsActive => _state == StepState.Active;
|
|
|
|
/// <summary>0..100 for the ProgressBar Value binding.</summary>
|
|
public double ProgressPercent => (_progress ?? 0) * 100;
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
private void OnChanged([CallerMemberName] string? name = null)
|
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name!));
|
|
}
|
|
|
|
public enum StepState
|
|
{
|
|
/// <summary>Hasn't started yet. Dim icon, no detail.</summary>
|
|
Pending,
|
|
/// <summary>In progress right now. Brand-coloured icon, detail +
|
|
/// optional progress bar visible.</summary>
|
|
Active,
|
|
/// <summary>Finished successfully. Green checkmark.</summary>
|
|
Done,
|
|
/// <summary>Failed — error in <see cref="StartupStep.Detail"/>. Red
|
|
/// X, the rest of the flow won't proceed.</summary>
|
|
Failed,
|
|
}
|
|
|
|
/// <summary>Helpers for the two known flows. Centralising the step
|
|
/// names here keeps the XAML free of hardcoded strings and makes it
|
|
/// obvious what stages a user will see.</summary>
|
|
public static class StartupFlow
|
|
{
|
|
public static ObservableCollection<StartupStep> NewHostFlow(bool isLocalNetwork) => new()
|
|
{
|
|
new StartupStep("Download server binary"),
|
|
new StartupStep(isLocalNetwork ? "Find your local network address" : "Set up Cloudflare tunnel"),
|
|
new StartupStep("Start the server"),
|
|
new StartupStep("Download client patcher"),
|
|
new StartupStep("Patch your Rec Room install"),
|
|
};
|
|
|
|
public static ObservableCollection<StartupStep> NewJoinFlow() => new()
|
|
{
|
|
new StartupStep("Download client patcher"),
|
|
new StartupStep("Patch your Rec Room install"),
|
|
};
|
|
}
|