Skip to content

Commit

Permalink
chore: Avoid duplicated logs and prevent error bubbling
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Nov 8, 2024
1 parent 4151902 commit 9e38c7a
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions src/Uno.UI.RemoteControl.VS/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,71 +442,54 @@ private async Task OnMessageReceivedAsync(object? sender, IdeMessage devServerMe
switch (devServerMessage)
{
case AddMenuItemRequestIdeMessage amir:
await OnAddMenuItemRequestIdeMessageAsync(sender, amir);
await OnAddMenuItemRequestedAsync(sender, amir);
break;
case ForceHotReloadIdeMessage fhr:
await OnForceHotReloadRequestedAsync(sender, fhr);
break;
case NotificationRequestIdeMessage nr:
await NotificationRequestIdeMessageAsync(sender, nr);
await OnNotificationRequestedAsync(sender, nr);
break;
default:
_debugAction?.Invoke($"Unknown message type {devServerMessage?.GetType()} from DevServer");
break;
}
}
catch (Exception e) when (_ideChannelClient is not null)
catch (Exception e)
{
_debugAction?.Invoke($"Failed to handle IdeMessage with message {e.Message}");
throw;
}
}

private async Task NotificationRequestIdeMessageAsync(object? sender, NotificationRequestIdeMessage message)
private async Task OnNotificationRequestedAsync(object? sender, NotificationRequestIdeMessage message)
{
try
{
await _asyncPackage.JoinableTaskFactory.SwitchToMainThreadAsync();
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);
}
}
catch (Exception e) when (_ideChannelClient is not null)
if (await _asyncPackage.GetServiceAsync(typeof(SVsShell)) is IVsShell shell &&
await _asyncPackage.GetServiceAsync(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory infoBarFactory)
{
_debugAction?.Invoke($"Failed to handle InfoBar Notification Requested with message {e.Message}");
throw;
await CreateInfoBarAsync(message, shell, infoBarFactory);
}
}

private async Task OnAddMenuItemRequestIdeMessageAsync(object? sender, AddMenuItemRequestIdeMessage cr)
private async Task OnAddMenuItemRequestedAsync(object? sender, AddMenuItemRequestIdeMessage cr)
{
try
if (_ideChannelClient == null)
{
if (_ideChannelClient == null)
{
return;
}
return;
}

if (_unoMenuCommand is not null)
{
//ignore when duplicated
if (!_unoMenuCommand.CommandList.Contains(cr))
{
_unoMenuCommand.CommandList.Add(cr);
}
}
else
if (_unoMenuCommand is not null)
{
//ignore when duplicated
if (!_unoMenuCommand.CommandList.Contains(cr))
{
_unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr);
_unoMenuCommand.CommandList.Add(cr);
}
}
catch (Exception e)
else
{
_debugAction?.Invoke($"Using AddMenuItem Ide Message Requested fail {e.Message}");
throw;
_unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr);
}
}

Expand Down

0 comments on commit 9e38c7a

Please sign in to comment.