Skip to content

Commit

Permalink
feat: Allow usage of HR indicator from external tool
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Sep 20, 2024
1 parent feb0949 commit 2cf2f71
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/Uno.UI.RemoteControl/HotReload/HotReloadStatusView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -110,10 +110,24 @@ public DiagnosticViewNotification? FailureNotification

private readonly Dictionary<long, ServerEntry> _serverHrEntries = new();
private readonly Dictionary<long, ApplicationEntry> _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<ClientHotReloadProcessor>().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 = [];

Expand All @@ -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;
}
}
};
}
Expand All @@ -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;
Expand Down

0 comments on commit 2cf2f71

Please sign in to comment.