Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/dr/dev srv #18270

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading