Skip to content

Commit

Permalink
Merge pull request #15 from MindscapeHQ/ro/cs-121/fix-send-in-backgro…
Browse files Browse the repository at this point in the history
…und-ios

Fix SendInBackground for iOS
  • Loading branch information
ProRedCat committed Mar 10, 2024
2 parents f76db3b + 826c1f2 commit 996531f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
5 changes: 4 additions & 1 deletion CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Full Change Log for Raygun4Maui package

### v1.4.2
- Fixed issue with SendInBackground where environment variables are collected on the wrong thread causing it to fail silently

### v1.4.1
- Fixed issue with resource locking of device environment information on Android causing app to crash

### v1.4.0
- Dependency update to Raygun4Net 8.0.0

### v1.3.0
- Dependency update to Raygun4Net 7.1.0
- Dependency update to Raygun4Net 7.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static void AttachMauiExceptionHandler(Raygun4MauiSettings raygunMauiSet
tags.Add(Raygun4NetBuildPlatforms.GetBuildPlatform());
}
RaygunMauiClient.Current.SendInBackground(e, tags, null);
RaygunMauiClient.Current.Send(e, tags, null);
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions Raygun4Maui/Raygun4Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.1</Version>
<PackageVersion>1.4.1</PackageVersion>
<Version>1.4.2</Version>
<PackageVersion>1.4.2</PackageVersion>
<Authors>Raygun</Authors>
<Company>Raygun</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
9 changes: 3 additions & 6 deletions Raygun4Maui/RaygunMauiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ public class RaygunMauiClient : RaygunClient
private static RaygunMauiClient _instance;
public static RaygunMauiClient Current => _instance;

private readonly Lazy<RaygunMauiEnvironmentMessageBuilder> _lazyMessageBuilder =
new Lazy<RaygunMauiEnvironmentMessageBuilder>(RaygunMauiEnvironmentMessageBuilder.Init);

private RaygunMauiEnvironmentMessageBuilder EnvironmentMessageBuilder => _lazyMessageBuilder.Value;

private readonly RaygunMauiEnvironmentMessageBuilder _environmentMessageBuilder = new();

private static readonly string Name = Assembly.GetExecutingAssembly().GetName().Name;

private static readonly string Version =
Expand Down Expand Up @@ -53,7 +50,7 @@ public RaygunMauiClient(RaygunSettings settings) : base(settings)
protected override async Task<RaygunMessage> BuildMessage(Exception exception, IList<string> tags,
IDictionary userCustomData, RaygunIdentifierMessage userInfo)
{
var environment = EnvironmentMessageBuilder.BuildEnvironmentMessage();
var environment = _environmentMessageBuilder.BuildEnvironmentMessage();

var details = new RaygunMessageDetails
{
Expand Down
77 changes: 48 additions & 29 deletions Raygun4Maui/RaygunMauiEnvironmentMessageBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
using System.Globalization;
using Mindscape.Raygun4Net;

namespace Raygun4Maui;

internal class RaygunMauiEnvironmentMessageBuilder
{
private static readonly object EnvironmentLock = new();

public string OSVersion { get; init; } = DeviceInfo.Current.VersionString;
public string Architecture { get; init; } = NativeDeviceInfo.Architecture();
public string OSVersion { get; init; } = DeviceInfo.Current.VersionString;
public string Architecture { get; init; } = NativeDeviceInfo.Architecture();

private string DeviceManufacturer = DeviceInfo.Current.Manufacturer;
private string Platform = NativeDeviceInfo.Platform();
private string Model = DeviceInfo.Current.Model;

private int ProcessorCount = Environment.ProcessorCount;

private double UtcOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalHours;


private ulong TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory();


private string Locale = CultureInfo.CurrentCulture.DisplayName;

private double? WindowBoundsWidth = null;

private double? WindowBoundsHeight = null;

private double? ResolutionScale = null;

private string CurrentOrientation = null;

public RaygunMauiEnvironmentMessageBuilder()
{
DeviceDisplay.MainDisplayInfoChanged += UpdateDisplayInfo;

// Ensure that we do have assigned values to the display fields by manually sending an update with the current information
MainThread.InvokeOnMainThreadAsync(() => UpdateDisplayInfo(this, new DisplayInfoChangedEventArgs(DeviceDisplay.MainDisplayInfo)));
}

internal RaygunMauiEnvironmentMessage BuildEnvironmentMessage()
{
// We create a lock so that during async tasks we do not access device information at the same time
// this has caused issues in Android
lock (EnvironmentLock)
return new RaygunMauiEnvironmentMessage
{
DateTime now = DateTime.Now;

return new RaygunMauiEnvironmentMessage
{
UtcOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalHours,
Locale = CultureInfo.CurrentCulture.DisplayName,
OSVersion = OSVersion,
Architecture = Architecture,
WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width,
WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height,
DeviceManufacturer = DeviceInfo.Current.Manufacturer,
Platform = Platform,
Model = Model,
ProcessorCount = ProcessorCount,
ResolutionScale = DeviceDisplay.MainDisplayInfo.Density,
TotalPhysicalMemory = TotalPhysicalMemory,
AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(),
CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(),
};
}
UtcOffset = UtcOffset,
Locale = Locale,
OSVersion = OSVersion,
Architecture = Architecture,
WindowBoundsWidth = WindowBoundsWidth ?? 0,
WindowBoundsHeight = WindowBoundsHeight ?? 0,
DeviceManufacturer = DeviceManufacturer,
Platform = Platform,
Model = Model,
ProcessorCount = ProcessorCount,
ResolutionScale = ResolutionScale ?? 0,
TotalPhysicalMemory = TotalPhysicalMemory,
AvailablePhysicalMemory =
NativeDeviceInfo.AvailablePhysicalMemory(), // Only possible issue for concurrent access
CurrentOrientation = CurrentOrientation,
};
}

public static RaygunMauiEnvironmentMessageBuilder Init()
private void UpdateDisplayInfo(object sender, DisplayInfoChangedEventArgs args)
{
return new RaygunMauiEnvironmentMessageBuilder();
// We assume the update will come from the UI thread

WindowBoundsWidth = args.DisplayInfo.Width;
WindowBoundsHeight = args.DisplayInfo.Height;
ResolutionScale = args.DisplayInfo.Density;
CurrentOrientation = args.DisplayInfo.Orientation.ToString();
}
}

0 comments on commit 996531f

Please sign in to comment.