From 6c4ec4a38bb03b3c1aeda8572d253455f5c4e535 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 8 Nov 2024 16:24:57 -0500 Subject: [PATCH] chore: Avoid duplicated logs and prevent error bubbling (cherry picked from commit 9e38c7a32199d869aa34519649108e16236b65de) # Conflicts: # src/Uno.UI.RemoteControl.VS/EntryPoint.cs --- src/Uno.UI.RemoteControl.VS/EntryPoint.cs | 56 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs index e66692432bfa..d920896b724e 100644 --- a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs +++ b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs @@ -437,6 +437,7 @@ async Task RestartAsync() } } +<<<<<<< HEAD private async Task OnMessageReceivedAsync(object? sender, NotificationRequestIdeMessage message) { try @@ -476,12 +477,63 @@ private async Task OnAddMenuItemRequestIdeMessageAsync(object? sender, AddMenuIt else { _unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr); +======= + private async Task OnMessageReceivedAsync(object? sender, IdeMessage devServerMessage) + { + try + { + switch (devServerMessage) + { + case AddMenuItemRequestIdeMessage amir: + await OnAddMenuItemRequestedAsync(sender, amir); + break; + case ForceHotReloadIdeMessage fhr: + await OnForceHotReloadRequestedAsync(sender, fhr); + break; + case NotificationRequestIdeMessage nr: + await OnNotificationRequestedAsync(sender, nr); + break; + default: + _debugAction?.Invoke($"Unknown message type {devServerMessage?.GetType()} from DevServer"); + break; +>>>>>>> 9e38c7a321 (chore: Avoid duplicated logs and prevent error bubbling) } } catch (Exception e) { - _debugAction?.Invoke($"Using AddMenuItem Ide Message Requested fail {e.Message}"); - throw; + _debugAction?.Invoke($"Failed to handle IdeMessage with message {e.Message}"); + } + } + + private async Task OnNotificationRequestedAsync(object? sender, NotificationRequestIdeMessage message) + { + await _asyncPackage.JoinableTaskFactory.SwitchToMainThreadAsync(); + + if (await _asyncPackage.GetServiceAsync(typeof(SVsShell)) is IVsShell shell && + await _asyncPackage.GetServiceAsync(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory infoBarFactory) + { + await CreateInfoBarAsync(message, shell, infoBarFactory); + } + } + + private async Task OnAddMenuItemRequestedAsync(object? sender, AddMenuItemRequestIdeMessage cr) + { + if (_ideChannelClient == null) + { + return; + } + + if (_unoMenuCommand is not null) + { + //ignore when duplicated + if (!_unoMenuCommand.CommandList.Contains(cr)) + { + _unoMenuCommand.CommandList.Add(cr); + } + } + else + { + _unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr); } }