-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
MauiOsData.cs
46 lines (40 loc) · 1.4 KB
/
MauiOsData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.Win32;
using Sentry.Extensibility;
using OperatingSystem = Sentry.Protocol.OperatingSystem;
namespace Sentry.Maui.Internal;
internal static class MauiOsData
{
public static void ApplyMauiOsData(this OperatingSystem os, IDiagnosticLogger? logger)
{
try
{
// https://docs.microsoft.com/dotnet/maui/platform-integration/device/information
var deviceInfo = DeviceInfo.Current;
if (deviceInfo.Platform == DevicePlatform.Unknown)
{
// return early so we don't get NotImplementedExceptions (i.e., in unit tests, etc.)
return;
}
os.Version = deviceInfo.VersionString;
#if WINDOWS
os.Name ??= "Windows";
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
if (key?.GetValue("DisplayVersion") is string displayVersion)
{
os.Build = displayVersion;
}
else if (key?.GetValue("ReleaseId") is string releaseId)
{
os.Build = releaseId;
}
#else
os.Name = deviceInfo.Platform.ToString();
#endif
}
catch (Exception ex)
{
// Log, but swallow the exception so we can continue sending events
logger?.LogError(ex, "Error getting MAUI OS information.");
}
}
}