2026-04-21 20:59:52 +08:00
|
|
|
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);
|
2026-04-22 07:31:54 +08:00
|
|
|
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>"}'.");
|
2026-04-21 20:59:52 +08:00
|
|
|
|
2026-04-22 07:31:54 +08:00
|
|
|
try
|
2026-04-21 20:59:52 +08:00
|
|
|
{
|
2026-04-22 07:31:54 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2026-04-21 20:59:52 +08:00
|
|
|
|
|
|
|
|
LauncherRuntimeContext.Current = commandContext;
|
|
|
|
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
|
|
|
|
return Environment.ExitCode;
|
|
|
|
|
}
|
2026-04-22 07:31:54 +08:00
|
|
|
catch (Exception ex)
|
2026-04-21 20:59:52 +08:00
|
|
|
{
|
2026-04-22 07:31:54 +08:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-04-21 20:59:52 +08:00
|
|
|
|
2026-04-22 07:31:54 +08:00
|
|
|
await Commands.WriteResultIfNeededAsync(commandContext.GetOption("result"), result).ConfigureAwait(false);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-04-21 20:59:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static AppBuilder BuildAvaloniaApp()
|
|
|
|
|
{
|
|
|
|
|
return AppBuilder.Configure<App>()
|
|
|
|
|
.UsePlatformDetect()
|
|
|
|
|
.WithInterFont()
|
|
|
|
|
.LogToTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|