diff --git a/LanMountainDesktop.Launcher/App.axaml.cs b/LanMountainDesktop.Launcher/App.axaml.cs index eb9d0cc..b09554b 100644 --- a/LanMountainDesktop.Launcher/App.axaml.cs +++ b/LanMountainDesktop.Launcher/App.axaml.cs @@ -18,6 +18,12 @@ public partial class App : Application { public override void Initialize() { + if (Design.IsDesignMode) + { + AvaloniaXamlLoader.Load(this); + return; + } + Logger.Initialize(); var context = LauncherRuntimeContext.Current; var execution = LauncherExecutionContext.Capture(); @@ -32,6 +38,12 @@ public partial class App : Application public override void OnFrameworkInitializationCompleted() { + if (Design.IsDesignMode) + { + base.OnFrameworkInitializationCompleted(); + return; + } + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; @@ -49,6 +61,18 @@ public partial class App : Application return; } + // 调试模式:只显示 DevDebugWindow,不走正常启动流程 + // 避免启动主程序后 Launcher 自动退出,导致开发者无法预览 UI + if (context.IsDebugMode && !context.IsPreviewCommand && + !string.Equals(context.Command, "apply-update", StringComparison.OrdinalIgnoreCase)) + { + Logger.Info("Debug mode active — showing DevDebugWindow instead of normal launch flow."); + var devDebugWindow = new DevDebugWindow(); + devDebugWindow.Show(); + base.OnFrameworkInitializationCompleted(); + return; + } + if (string.Equals(context.Command, "apply-update", StringComparison.OrdinalIgnoreCase)) { var updateWindow = new UpdateWindow(); diff --git a/LanMountainDesktop.Launcher/CommandContext.cs b/LanMountainDesktop.Launcher/CommandContext.cs index 37439a0..fcad276 100644 --- a/LanMountainDesktop.Launcher/CommandContext.cs +++ b/LanMountainDesktop.Launcher/CommandContext.cs @@ -37,11 +37,25 @@ internal sealed class CommandContext /// /// 是否处于调试模式(从 Rider/VS 等 IDE 启动) - /// 仅当明确指定 --debug 参数或调试器附加时才启用 + /// 当满足以下任一条件时启用: + /// 1. 明确指定 --debug 参数 + /// 2. 调试器附加(Debugger.IsAttached) + /// 3. DOTNET_ENVIRONMENT 环境变量为 Development(IDE 调试启动时自动设置) /// public bool IsDebugMode => Options.ContainsKey("debug") || - System.Diagnostics.Debugger.IsAttached; + System.Diagnostics.Debugger.IsAttached || + IsDevelopmentEnvironment; + + /// + /// 是否为 Development 环境(DOTNET_ENVIRONMENT=Development) + /// Rider/VS 调试启动时会自动设置此环境变量 + /// + public bool IsDevelopmentEnvironment => + string.Equals( + System.Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"), + "Development", + StringComparison.OrdinalIgnoreCase); public bool IsPreviewCommand => Command.StartsWith("preview-", StringComparison.OrdinalIgnoreCase); diff --git a/LanMountainDesktop.Launcher/Program.cs b/LanMountainDesktop.Launcher/Program.cs index a5b089b..6eeb837 100644 --- a/LanMountainDesktop.Launcher/Program.cs +++ b/LanMountainDesktop.Launcher/Program.cs @@ -4,10 +4,10 @@ using LanMountainDesktop.Launcher.Services; namespace LanMountainDesktop.Launcher; -internal static class Program +public static class Program { [STAThread] - private static async Task Main(string[] args) + public static async Task Main(string[] args) { var commandContext = CommandContext.FromArgs(args); var execution = LauncherExecutionContext.Capture(); @@ -66,7 +66,7 @@ internal static class Program } } - private static AppBuilder BuildAvaloniaApp() + public static AppBuilder BuildAvaloniaApp() { return AppBuilder.Configure() .UsePlatformDetect() diff --git a/LanMountainDesktop.Launcher/Properties/launchSettings.json b/LanMountainDesktop.Launcher/Properties/launchSettings.json index 7a8f3ab..f8c1f60 100644 --- a/LanMountainDesktop.Launcher/Properties/launchSettings.json +++ b/LanMountainDesktop.Launcher/Properties/launchSettings.json @@ -1,6 +1,14 @@ { "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { + "Launcher (Debug Mode)": { + "commandName": "Project", + "commandLineArgs": "launch --debug", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, "Launcher (Launch Mode)": { "commandName": "Project", "commandLineArgs": "launch", @@ -9,6 +17,46 @@ "DOTNET_ENVIRONMENT": "Development" } }, + "Launcher (Preview Debug Window)": { + "commandName": "Project", + "commandLineArgs": "preview-debug", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, + "Launcher (Preview Splash)": { + "commandName": "Project", + "commandLineArgs": "preview-splash", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, + "Launcher (Preview Error)": { + "commandName": "Project", + "commandLineArgs": "preview-error", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, + "Launcher (Preview Update)": { + "commandName": "Project", + "commandLineArgs": "preview-update", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, + "Launcher (Preview OOBE)": { + "commandName": "Project", + "commandLineArgs": "preview-oobe", + "workingDirectory": "$(SolutionDir)", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + }, "Launcher (Update Check)": { "commandName": "Project", "commandLineArgs": "update check",