Skip to content

Commit

Permalink
Merge pull request #18270 from unoplatform/dev/dr/devSrv
Browse files Browse the repository at this point in the history
Dev/dr/dev srv
  • Loading branch information
dr1rrb authored Sep 23, 2024
2 parents 2be9abe + 2cf2f71 commit eeebc8b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Expand Down Expand Up @@ -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
{
/// <inheritdoc />
public event PropertyChangedEventHandler? PropertyChanged;
Expand Down
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 eeebc8b

Please sign in to comment.