mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
Improve launcher startup flow, logging, and host resolution. Key changes: add detailed startup logging and standardized preview messages; unify CLI vs GUI handling and error/result reporting (write result file when requested); refactor DeploymentLocator to a more robust host resolution (new HostResolutionResult, explicit/portable/published/debug resolution paths, legacy fallback); overhaul LauncherFlowCoordinator to better handle IPC stages, activation retries, window lifecycle, plugin/update flows and error reporting; add CommandContext helpers (IsGui/IsPreview/ExplicitAppRoot) and JSON context options; tighten async usage and ConfigureAwait calls; add better UI error handling and consistent exit codes. Several UX/debug conveniences and robustness fixes included.
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using Avalonia;
|
|
using LanMountainDesktop.Launcher.Models;
|
|
using LanMountainDesktop.Launcher.Services;
|
|
|
|
namespace LanMountainDesktop.Launcher;
|
|
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
private static async Task<int> Main(string[] args)
|
|
{
|
|
var commandContext = CommandContext.FromArgs(args);
|
|
Logger.Initialize();
|
|
Logger.Info(
|
|
$"Program entry. Command='{commandContext.Command}'; SubCommand='{commandContext.SubCommand}'; " +
|
|
$"IsGuiMode={commandContext.IsGuiCommand}; IsDebugMode={commandContext.IsDebugMode}; " +
|
|
$"HasResultPath={!string.IsNullOrWhiteSpace(commandContext.GetOption("result"))}; " +
|
|
$"ExplicitAppRoot='{commandContext.ExplicitAppRoot ?? "<none>"}'.");
|
|
|
|
try
|
|
{
|
|
if (commandContext.IsLegacyPluginInstall)
|
|
{
|
|
var installer = new PluginInstallerService();
|
|
return await Commands.RunLegacyPluginInstallAsync(commandContext, installer).ConfigureAwait(false);
|
|
}
|
|
|
|
if (!commandContext.IsGuiCommand)
|
|
{
|
|
return await Commands.RunCliCommandAsync(commandContext).ConfigureAwait(false);
|
|
}
|
|
|
|
LauncherRuntimeContext.Current = commandContext;
|
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
|
return Environment.ExitCode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error("Launcher failed before GUI flow completed.", ex);
|
|
|
|
var result = new LauncherResult
|
|
{
|
|
Success = false,
|
|
Stage = "launcher",
|
|
Code = "launcher_bootstrap_failed",
|
|
Message = ex.Message,
|
|
ErrorMessage = ex.ToString(),
|
|
Details = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["command"] = commandContext.Command,
|
|
["subCommand"] = commandContext.SubCommand,
|
|
["isGuiMode"] = commandContext.IsGuiCommand.ToString(),
|
|
["isDebugMode"] = commandContext.IsDebugMode.ToString(),
|
|
["explicitAppRoot"] = commandContext.ExplicitAppRoot ?? string.Empty
|
|
}
|
|
};
|
|
|
|
await Commands.WriteResultIfNeededAsync(commandContext.GetOption("result"), result).ConfigureAwait(false);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private static AppBuilder BuildAvaloniaApp()
|
|
{
|
|
return AppBuilder.Configure<App>()
|
|
.UsePlatformDetect()
|
|
.WithInterFont()
|
|
.LogToTrace();
|
|
}
|
|
}
|