Implement startup state management and enhance configuration loading

- Introduced a new `StartupState` class to encapsulate the state collected before the console backend initialization.
- Updated the configuration loading process to handle legacy upgrades and provide detailed feedback on configuration status.
- Enhanced the TUI backend to utilize the new startup state for improved initialization flow.
- Refactored the `LoadFromFile` method in `Settings` to return a structured result, improving error handling and clarity.
This commit is contained in:
BruceChen 2026-03-27 00:29:01 +08:00
parent b33ee7e4a1
commit fe7ab9f373
3 changed files with 219 additions and 129 deletions

View file

@ -25,14 +25,18 @@ namespace MinecraftClient.Tui
internal static TuiConsoleBackend? Instance { get; private set; }
private Program.StartupState? _pendingStartupState;
private readonly ManualResetEventSlim _viewReady = new(false);
/// <summary>
/// Initializes the Avalonia app and starts the main UI loop.
/// This blocks the calling thread until the TUI exits.
/// Before blocking, it starts MCC's remaining initialization on a background thread.
/// </summary>
public void RunTuiMainLoop(string[] args)
internal void RunTuiMainLoop(string[] args, Program.StartupState startupState)
{
Instance = this;
_pendingStartupState = startupState;
AppDomain.CurrentDomain.ProcessExit += (_, _) => RestoreTerminalState();
@ -46,7 +50,7 @@ namespace MinecraftClient.Tui
new Thread(() =>
{
Thread.Sleep(500);
_viewReady.Wait();
ContinueMccStartup(args);
})
{ Name = "MCC-Main", IsBackground = true }.Start();
@ -113,7 +117,15 @@ namespace MinecraftClient.Tui
{
try
{
Program.ContinueAfterTuiInit(args);
var instance = Instance;
if (instance?._pendingStartupState is { } state)
{
instance._pendingStartupState = null;
if (!Program.ProcessStartupState(state))
return;
}
Program.RunStartupSequence(args);
}
catch (Exception ex)
{
@ -124,6 +136,7 @@ namespace MinecraftClient.Tui
internal void SetView(MainTuiView view)
{
_view = view;
_viewReady.Set();
}
internal MainTuiView? GetView() => _view;