From ce183c8eb93e617f2a3333c8707db09b64371ed0 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 10 Dec 2025 21:46:46 -0600 Subject: [PATCH] Implement debugger for packaging scripts --- .../PowerShell/PowerShellScript.cs | 5 ++ LANCommander.Server/Styles/_layout.scss | 4 + .../UI/Components/PowerShellConsole.razor | 80 ++++++++++++------- .../UI/Components/ScriptEditorDialog.razor | 21 ++++- 4 files changed, 80 insertions(+), 30 deletions(-) diff --git a/LANCommander.SDK/PowerShell/PowerShellScript.cs b/LANCommander.SDK/PowerShell/PowerShellScript.cs index ebe77305..7182910a 100644 --- a/LANCommander.SDK/PowerShell/PowerShellScript.cs +++ b/LANCommander.SDK/PowerShell/PowerShellScript.cs @@ -239,6 +239,11 @@ namespace LANCommander.SDK.PowerShell } finally { + await DebugAsync(async dbg => + { + await dbg.EndAsync(DebugContext); + }); + Context.Dispose(); } } diff --git a/LANCommander.Server/Styles/_layout.scss b/LANCommander.Server/Styles/_layout.scss index 3d1cd325..02e42f2d 100644 --- a/LANCommander.Server/Styles/_layout.scss +++ b/LANCommander.Server/Styles/_layout.scss @@ -51,4 +51,8 @@ .ant-layout-footer { text-align: center; +} + +.hidden { + display: none; } \ No newline at end of file diff --git a/LANCommander.Server/UI/Components/PowerShellConsole.razor b/LANCommander.Server/UI/Components/PowerShellConsole.razor index 3a8993d6..b0c38ab2 100644 --- a/LANCommander.Server/UI/Components/PowerShellConsole.razor +++ b/LANCommander.Server/UI/Components/PowerShellConsole.razor @@ -1,17 +1,21 @@ @using LANCommander.SDK.PowerShell -@using LANCommander.SDK.PowerShell.Rpc +@using LANCommander.SDK.Services @using LANCommander.Server.Services.PowerShell @using XtermBlazor @using LogLevel = Microsoft.Extensions.Logging.LogLevel -@inherits RpcComponentBase -@inject ScriptDebugger +@inject ScriptDebugger ScriptDebugger +@inject ScriptClient ScriptClient +@inject GameService GameService -
- +
+
@code { - private bool Visible { get; set; } = false; + [Parameter] public Guid Id { get; set; } + [Parameter] public bool Active { get; set; } + [Parameter] public EventCallback ActiveChanged { get; set; } + private Xterm Terminal; private TaskCompletionSource InputTaskCompletionSource; @@ -27,8 +31,6 @@ "addon-fit" }; - protected override string HubUrl => "/RPC/ScriptDebugger"; - private async Task OnFirstRender() { await Terminal.Addon("addon-fit").InvokeVoidAsync("fit"); @@ -39,24 +41,39 @@ return await Terminal.Addon("readline").InvokeAsync("read", "> "); } + async Task SetActive(bool active) + { + Active = active; + + if (ActiveChanged.HasDelegate) + await ActiveChanged.InvokeAsync(Active); + } + public async Task DebugPackagingScript(Guid gameId) { - await Hub.DebugPackageScript(gameId); + ScriptDebugger.OnBreak = Break; + ScriptDebugger.OnStart = Start; + ScriptDebugger.OnEnd = End; + ScriptDebugger.OnOutput = Output; + + ScriptClient.Debug = true; + + await GameService.PackageAsync(gameId); } public async Task Start(IScriptDebugContext context) { Terminal?.Clear(); - Visible = true; + await SetActive(true); await InvokeAsync(StateHasChanged); + await Terminal.Focus(); await Terminal.Addon("addon-fit").InvokeVoidAsync("fit"); } public async Task End(IScriptDebugContext context) { - Visible = false; - + await SetActive(false); await InvokeAsync(StateHasChanged); } @@ -78,27 +95,34 @@ public async Task Output(IScriptDebugContext context, LogLevel level, string message) { - switch (level) + try { - case LogLevel.Error: - await Terminal.WriteLine($"\x1b[0;31m{message}"); - break; + switch (level) + { + case LogLevel.Error: + await Terminal.WriteLine($"\x1b[0;31m{message}"); + break; - case LogLevel.Warning: - await Terminal.WriteLine($"\x1b[0;33m{message}"); - break; + case LogLevel.Warning: + await Terminal.WriteLine($"\x1b[0;33m{message}"); + break; - case LogLevel.Debug: - await Terminal.WriteLine($"\x1b[0;37m{message}"); - break; + case LogLevel.Debug: + await Terminal.WriteLine($"\x1b[0;37m{message}"); + break; - case LogLevel.Trace: - await Terminal.WriteLine($"\x1b[0;36m{message}"); - break; + case LogLevel.Trace: + await Terminal.WriteLine($"\x1b[0;36m{message}"); + break; - case LogLevel.Information: - await Terminal.WriteLine($"\x1b[0;37m{message}"); - break; + case LogLevel.Information: + await Terminal.WriteLine($"\x1b[0;37m{message}"); + break; + } + } + catch (Exception ex) + { + } } } \ No newline at end of file diff --git a/LANCommander.Server/UI/Components/ScriptEditorDialog.razor b/LANCommander.Server/UI/Components/ScriptEditorDialog.razor index 521b3b16..ea1940b1 100644 --- a/LANCommander.Server/UI/Components/ScriptEditorDialog.razor +++ b/LANCommander.Server/UI/Components/ScriptEditorDialog.razor @@ -39,13 +39,15 @@ @if (Options.GameId.HasValue && Options.GameId != Guid.Empty && IsDebuggable) { -