Skip to content

Commit

Permalink
restore file
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Jul 15, 2024
1 parent 1005054 commit 3176940
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Raygun.NetCore.Blazor
{

/// <summary>
/// Handles interoperability between the <see cref="RaygunBlazorClient" /> and JavaScript.
/// </summary>
public class RaygunBrowserInterop : IAsyncDisposable
{

#region Private Members

private readonly DotNetObjectReference<RaygunBrowserInterop> _dotNetReference;
Expand All @@ -24,9 +26,7 @@ public class RaygunBrowserInterop : IAsyncDisposable
private readonly RaygunSettings _raygunSettings;
private readonly IWindowService _windowService;
private Action<string, BreadcrumbType, string?, Dictionary<string, object>?, string?> _breadcrumbAction;

private Func<Exception, List<string>?, bool, Dictionary<string, string>?, CancellationToken, Task>
_exceptionAction;
private Func<Exception, List<string>?, bool, Dictionary<string, string>?, CancellationToken, Task> _exceptionAction;

#endregion

Expand Down Expand Up @@ -77,8 +77,7 @@ public class RaygunBrowserInterop : IAsyncDisposable
// See https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-dotnet-from-javascript?view=aspnetcore-8.0#avoid-trimming-javascript-invokable-net-methods
[DynamicDependency(nameof(RecordJsBreadcrumb))]
[DynamicDependency(nameof(RecordJsException))]
public RaygunBrowserInterop(IJSRuntime jsRuntime, IWindowService windowService,
IOptions<RaygunSettings> raygunSettings)
public RaygunBrowserInterop(IJSRuntime jsRuntime, IWindowService windowService, IOptions<RaygunSettings> raygunSettings)
{
_dotNetReference = DotNetObjectReference.Create(this);
_jsRuntime = jsRuntime;
Expand All @@ -99,7 +98,7 @@ public RaygunBrowserInterop(IJSRuntime jsRuntime, IWindowService windowService,
/// <param name="customData"></param>
/// <returns></returns>
[JSInvokable]
public async ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual,
public async ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcrumbType = BreadcrumbType.Manual,
string category = null, Dictionary<string, object> customData = null)
{
_breadcrumbAction.Invoke(message, breadcrumbType, category, customData, "JavaScript");
Expand All @@ -114,8 +113,7 @@ public async ValueTask RecordJsBreadcrumb(string message, BreadcrumbType breadcr
/// <param name="customData"></param>
/// <returns></returns>
[JSInvokable]
public async ValueTask RecordJsException(Exception exception, List<string>? tags = null,
bool sendUserData = false, Dictionary<string, string>? customData = null)
public async ValueTask RecordJsException(Exception exception, List<string>? tags = null, bool sendUserData = false, Dictionary<string, string>? customData = null)

Check warning on line 116 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 116 in src/Raygun.NetCore.Blazor/RaygunBrowserInterop.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
await _exceptionAction.Invoke(exception, tags, sendUserData, customData, CancellationToken.None);
}
Expand Down Expand Up @@ -155,9 +153,8 @@ internal async Task InitializeAsync(Func<ErrorEvent, Task> onUnhandledJsExceptio

// RWM: We're going to register the Raygun script and get the BrowserSpecs first. The reason why is because if we
// handle JS errors & they start coming in before we're ready, then there will be wailing and gnashing of teeth.
RaygunScriptReference = await _jsRuntime.InvokeAsync<IJSObjectReference>("import",
"./_content/Raygun.NetCore.Blazor/Raygun.NetCore.Blazor.js");

RaygunScriptReference = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Raygun.NetCore.Blazor/Raygun.NetCore.Blazor.js");

// RWM: Register the .NET reference with JS so that JS code can also manually create Bookmarks and report Exceptions.
await _jsRuntime.InvokeVoidAsync("window.raygunBlazor.initialize", _dotNetReference);

Expand Down Expand Up @@ -188,23 +185,22 @@ public async ValueTask DisposeAsync()
await Window.RemoveOnErrorEventListenerAsync(_errorEventListener);
await _errorEventListener.DisposeAsync();
}

if (Window is not null)
{
await Window.DisposeAsync();
}

if (RaygunScriptReference is not null)
{
await RaygunScriptReference.DisposeAsync();
}

if (_dotNetReference is not null)
{
_dotNetReference.Dispose();
}
}

#endregion

}
}

}

0 comments on commit 3176940

Please sign in to comment.