From 1067a99609d6578fbf238266f5324b5d3dd926fe Mon Sep 17 00:00:00 2001 From: Rafael Rosa Date: Thu, 17 Oct 2024 09:41:42 -0300 Subject: [PATCH 1/2] chore: change OnMessageReceivedAsync (cherry picked from commit 85e5d1e9680116da05bc75eddcbd806c2198d406) --- src/Uno.UI.RemoteControl.VS/EntryPoint.cs | 34 +++++++++++++++++-- .../IDEChannel/IDEChannelClient.cs | 31 +++++------------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs index 8590141e7172..849307420666 100644 --- a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs +++ b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs @@ -344,9 +344,7 @@ private async Task EnsureServerAsync() _process.BeginErrorReadLine(); _ideChannelClient = new IdeChannelClient(pipeGuid, new Logger(this)); - _ideChannelClient.ForceHotReloadRequested += OnForceHotReloadRequestedAsync; _ideChannelClient.OnMessageReceived += OnMessageReceivedAsync; - _ideChannelClient.OnAddMenuItemIdeMessageRequested += OnAddMenuItemRequestIdeMessageAsync; _ideChannelClient.ConnectToHost(); // Set the port to the projects @@ -422,7 +420,37 @@ async Task RestartAsync() } } - private async Task OnMessageReceivedAsync(object? sender, NotificationRequestIdeMessage message) + private async Task OnMessageReceivedAsync(object? sender, IdeMessage devServerMessage) + { + try + { + switch (devServerMessage) + { + case KeepAliveIdeMessage: + _debugAction?.Invoke($"Keep alive from Dev Server"); + break; + case AddMenuItemRequestIdeMessage amir: + await OnAddMenuItemRequestIdeMessageAsync(sender, amir); + break; + case ForceHotReloadIdeMessage fhr: + await OnForceHotReloadRequestedAsync(sender, fhr); + break; + case NotificationRequestIdeMessage nr: + await NotificationRequestIdeMessageAsync(sender, nr); + break; + default: + _debugAction?.Invoke($"Unknown message type {devServerMessage?.GetType()} from DevServer"); + break; + } + } + catch (Exception e) when (_ideChannelClient is not null) + { + _debugAction?.Invoke($"Failed to handle IdeMessage with message {e.Message}"); + throw; + } + } + + private async Task NotificationRequestIdeMessageAsync(object? sender, NotificationRequestIdeMessage message) { try { diff --git a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs index 563b3c5ea5d4..d4af83541f90 100644 --- a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs +++ b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs @@ -20,9 +20,7 @@ internal class IdeChannelClient private IIdeChannelServer? _devServer; private readonly ILogger _logger; - public event AsyncEventHandler? ForceHotReloadRequested; - public event AsyncEventHandler? OnMessageReceived; - public event AsyncEventHandler? OnAddMenuItemIdeMessageRequested; + public event AsyncEventHandler? OnMessageReceived; public IdeChannelClient(Guid pipeGuid, ILogger logger) { @@ -91,27 +89,14 @@ private void ProcessDevServerMessage(object sender, IdeMessageEnvelope devServer _logger.Verbose($"IDE: IDEChannel message received {devServerMessage}"); var process = Task.CompletedTask; - switch (devServerMessage) + if (devServerMessage is IdeMessage message) { - case AddMenuItemRequestIdeMessage cr: - _logger.Debug("Command Ide Message Requested"); - process = OnAddMenuItemIdeMessageRequested.InvokeAsync(this, cr); - break; - - case ForceHotReloadIdeMessage forceHotReloadMessage when ForceHotReloadRequested is { } hrRequested: - _logger.Debug("Hot reload requested"); - process = hrRequested.InvokeAsync(this, forceHotReloadMessage); - break; - case KeepAliveIdeMessage: - _logger.Verbose($"Keep alive from Dev Server"); - break; - case NotificationRequestIdeMessage e when e is { } message: - _logger.Verbose($"Dev Server will open the Notification Message with message {e.Message}"); - process = OnMessageReceived.InvokeAsync(this, message); - break; - default: - _logger.Verbose($"Unknown message type {devServerMessage?.GetType()} from DevServer"); - break; + _logger.Verbose($"Dev Server Message {message.GetType()} requested"); + process = OnMessageReceived.InvokeAsync(this, message); + } + else + { + _logger.Verbose($"Unknown message type {devServerMessage?.GetType()} from DevServer"); } _ = process.ContinueWith( From cdbd344f3019a8cf11d2db80af6d3f39efba5a2f Mon Sep 17 00:00:00 2001 From: Rafael Rosa Date: Thu, 17 Oct 2024 11:12:30 -0300 Subject: [PATCH 2/2] chore: move KeepAliveIdeMessage to IDEChannelClient (cherry picked from commit da8f935ec4c1ea54e7e7cd4c2fbffe4841cc146f) --- src/Uno.UI.RemoteControl.VS/EntryPoint.cs | 3 --- .../IDEChannel/IDEChannelClient.cs | 18 +++++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs index 849307420666..8f619ffea681 100644 --- a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs +++ b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs @@ -426,9 +426,6 @@ private async Task OnMessageReceivedAsync(object? sender, IdeMessage devServerMe { switch (devServerMessage) { - case KeepAliveIdeMessage: - _debugAction?.Invoke($"Keep alive from Dev Server"); - break; case AddMenuItemRequestIdeMessage amir: await OnAddMenuItemRequestIdeMessageAsync(sender, amir); break; diff --git a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs index d4af83541f90..b665647b8b09 100644 --- a/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs +++ b/src/Uno.UI.RemoteControl.VS/IDEChannel/IDEChannelClient.cs @@ -89,14 +89,18 @@ private void ProcessDevServerMessage(object sender, IdeMessageEnvelope devServer _logger.Verbose($"IDE: IDEChannel message received {devServerMessage}"); var process = Task.CompletedTask; - if (devServerMessage is IdeMessage message) + switch (devServerMessage) { - _logger.Verbose($"Dev Server Message {message.GetType()} requested"); - process = OnMessageReceived.InvokeAsync(this, message); - } - else - { - _logger.Verbose($"Unknown message type {devServerMessage?.GetType()} from DevServer"); + case KeepAliveIdeMessage: + _logger.Verbose($"Keep alive from Dev Server"); + break; + case IdeMessage message: + _logger.Verbose($"Dev Server Message {message.GetType()} requested"); + process = OnMessageReceived.InvokeAsync(this, message); + break; + default: + _logger.Verbose($"Unknown message type {devServerMessage?.GetType()} from DevServer"); + break; } _ = process.ContinueWith(