Files
lincube 33591a0a63 Add startup visual modes and attempt registry
Implement startup visual behavior, de-duplicate startup attempts, and improve failure UX.

Key changes:
- Add spec and docs for startup visuals and timing contract (.trae/specs and docs/LAUNCHER_STARTUP_VISUALS.md).
- Introduce StartupVisualPreferences contract and resolver; create SplashWindow via resolved mode.
- Add StartupAttemptRecord model and a file-backed StartupAttemptRegistry to persist and coordinate in-progress startup attempts (attach/adopt, soft/hard timeouts, IPC/connect state, lifecycle updates).
- Update LauncherFlowCoordinator to: adopt/attach to existing attempts, track IPC connection and soft/hard timeouts (30s/120s), show delayed UI state, attempt foreground recovery via public IPC, compose detailed launch result metadata, and mark registry states (soft timeout, detached waiting, succeeded, failed).
- Add TryActivateExistingInstanceAsync to attempt activating an existing desktop via IPC.
- Change failure flow: ShowFailureWindowAsync now returns user choice; ErrorWindow updated to present Activate/Wait/Open Logs/Exit semantics and new layouts/styles; improved button wiring and debug/dev mode handling.
- Add UI and resource tweaks (ErrorWindow and SplashWindow changes), project asset link for nightly logo, and unit tests for StartupVisualPreferences.

These changes prevent duplicate desktop processes during slow startups, provide clearer UX for delayed startups, and persist startup attempt state across Launcher invocations for safer recovery/attach behavior.
2026-04-23 09:03:35 +08:00

92 lines
2.6 KiB
C#

using System.Text.Json;
namespace LanMountainDesktop.Shared.Contracts.Launcher;
public enum StartupVisualMode
{
Fade,
StaticSplash,
SlideSplash
}
public readonly record struct StartupVisualPreferences(
bool EnableFadeTransition,
bool EnableSlideTransition)
{
public static StartupVisualPreferences Default => new(true, false);
public StartupVisualPreferences Normalize()
{
if (EnableSlideTransition)
{
return new StartupVisualPreferences(false, true);
}
return new StartupVisualPreferences(EnableFadeTransition, false);
}
public StartupVisualMode Mode => Normalize() switch
{
{ EnableSlideTransition: true } => StartupVisualMode.SlideSplash,
{ EnableFadeTransition: false } => StartupVisualMode.StaticSplash,
_ => StartupVisualMode.Fade
};
}
public static class StartupVisualPreferencesResolver
{
public static StartupVisualPreferences Resolve(string? settingsPath = null)
{
var resolvedPath = string.IsNullOrWhiteSpace(settingsPath)
? GetDefaultSettingsPath()
: settingsPath!;
if (!File.Exists(resolvedPath))
{
return StartupVisualPreferences.Default;
}
try
{
using var stream = File.OpenRead(resolvedPath);
using var document = JsonDocument.Parse(stream);
var root = document.RootElement;
var enableFade = TryGetBoolean(root, "enableFadeTransition") ?? true;
var enableSlide = TryGetBoolean(root, "enableSlideTransition") ?? false;
return FromFlags(enableFade, enableSlide);
}
catch
{
return StartupVisualPreferences.Default;
}
}
public static StartupVisualPreferences FromFlags(bool enableFadeTransition, bool enableSlideTransition)
{
return new StartupVisualPreferences(enableFadeTransition, enableSlideTransition).Normalize();
}
public static string GetDefaultSettingsPath()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return Path.Combine(appData, "LanMountainDesktop", "settings.json");
}
private static bool? TryGetBoolean(JsonElement root, string propertyName)
{
if (!root.TryGetProperty(propertyName, out var property))
{
return null;
}
return property.ValueKind switch
{
JsonValueKind.True => true,
JsonValueKind.False => false,
JsonValueKind.String when bool.TryParse(property.GetString(), out var value) => value,
_ => null
};
}
}