From feb094987547f4a66752349ba193b4990be6f04c Mon Sep 17 00:00:00 2001 From: David Date: Fri, 20 Sep 2024 18:33:36 -0400 Subject: [PATCH 1/2] fix: Improve HR message to imrpove user experience --- .../HotReload/HotReloadStatusView.Entries.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.Entries.cs b/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.Entries.cs index 0d6d8272ad2e..70ede1d818c5 100644 --- a/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.Entries.cs +++ b/src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.Entries.cs @@ -54,7 +54,7 @@ internal record EngineEntry() : HotReloadLogEntry(EntrySource.Engine, -1, DateTi => (oldStatus?.State ?? HotReloadState.Initializing, status.State) switch { ( < HotReloadState.Ready, HotReloadState.Ready) => new EngineEntry { Title = "Connected", Icon = EntryIcon.Connection | EntryIcon.Success }, - (not HotReloadState.Disabled, HotReloadState.Disabled) => new EngineEntry { Title = "Cannot initialize", Icon = EntryIcon.Connection | EntryIcon.Error }, + (not HotReloadState.Disabled, HotReloadState.Disabled) => new EngineEntry { Title = "Cannot initialize with debugger attached", Icon = EntryIcon.Connection | EntryIcon.Error }, _ => null }; } @@ -151,7 +151,7 @@ public enum EntryIcon [Microsoft.UI.Xaml.Data.Bindable] -internal record HotReloadLogEntry(EntrySource Source, long Id, DateTimeOffset Timestamp) : INotifyPropertyChanged +public record HotReloadLogEntry(EntrySource Source, long Id, DateTimeOffset Timestamp) : INotifyPropertyChanged { /// public event PropertyChangedEventHandler? PropertyChanged; From 2cf2f7116548399d99d9eae2897705e3a8bc45c6 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 20 Sep 2024 18:34:58 -0400 Subject: [PATCH 2/2] feat: Allow usage of HR indicator from external tool --- .../HotReload/HotReloadStatusView.cs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) 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;