diff --git a/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.cs b/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.cs index 641e8a4a9afb..08e45595a75e 100644 --- a/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.cs +++ b/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.cs @@ -20,7 +20,7 @@ namespace Uno.UI.RemoteControl.HotReload; [TemplateVisualState(GroupName = "Result", Name = ResultNoneVisualStateName)] [TemplateVisualState(GroupName = "Result", Name = ResultSuccessVisualStateName)] [TemplateVisualState(GroupName = "Result", Name = ResultFailedVisualStateName)] -internal sealed partial class HotReloadStatusView : Control +public sealed partial class HotReloadStatusView : Control { private const string StatusUnknownVisualStateName = "Unknown"; private const string StatusInitializingVisualStateName = "Initializing"; @@ -110,10 +110,24 @@ public DiagnosticViewNotification? FailureNotification private readonly Dictionary _serverHrEntries = new(); private readonly Dictionary _appHrEntries = new(); + private readonly ClientHotReloadProcessor? _processor; // Only when used by external tool like HD. - public HotReloadStatusView(IDiagnosticViewContext ctx) + public static HotReloadStatusView Create(IDiagnosticViewContext ctx) + { + var processor = RemoteControlClient.Instance?.Processors?.OfType().FirstOrDefault(); + if (processor is null) + { + throw new InvalidOperationException("Cannot resolve the hot-reload client."); + } + + return new HotReloadStatusView(ctx, processor); + } + + internal HotReloadStatusView(IDiagnosticViewContext ctx, ClientHotReloadProcessor? processor = null) { _ctx = ctx; + _processor = processor; + DefaultStyleKey = typeof(HotReloadStatusView); History = []; @@ -130,14 +144,27 @@ public HotReloadStatusView(IDiagnosticViewContext ctx) devServer.StatusChanged += that.OnDevServerStatusChanged; that.OnDevServerStatusChanged(null, devServer.Status); } + + if (that._processor is not null) + { + that._processor.StatusChanged += that.OnHotReloadStatusChanged; + that.OnHotReloadStatusChanged(that._processor.CurrentStatus); + } } }; Unloaded += static (snd, _) => { - if (snd is HotReloadStatusView that - && RemoteControlClient.Instance is { } devServer) + if (snd is HotReloadStatusView that) { - devServer.StatusChanged -= that.OnDevServerStatusChanged; + if (RemoteControlClient.Instance is { } devServer) + { + devServer.StatusChanged -= that.OnDevServerStatusChanged; + } + + if (that._processor is not null) + { + that._processor.StatusChanged -= that.OnHotReloadStatusChanged; + } } }; } @@ -155,7 +182,10 @@ private void OnDevServerStatusChanged(object? sender, RemoteControlStatus devSer }); } - public void OnHotReloadStatusChanged(Status status) + private void OnHotReloadStatusChanged(object? sender, Status status) + => OnHotReloadStatusChanged(status); + + internal void OnHotReloadStatusChanged(Status status) { var oldStatus = _hotReloadStatus; _hotReloadStatus = status;