Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pkgs/sdk/client/src/PlatformSpecific/AppInfo.maui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ namespace LaunchDarkly.Sdk.Client.PlatformSpecific
{
internal static partial class AppInfo
{
internal static ApplicationInfo? GetAppInfo() => new ApplicationInfo(
Microsoft.Maui.ApplicationModel.AppInfo.Current.PackageName,
Microsoft.Maui.ApplicationModel.AppInfo.Current.Name,
Microsoft.Maui.ApplicationModel.AppInfo.Current.BuildString,
Microsoft.Maui.ApplicationModel.AppInfo.Current.VersionString);
internal static ApplicationInfo? GetAppInfo()
{
try
{
return new ApplicationInfo(
Microsoft.Maui.ApplicationModel.AppInfo.Current.PackageName,
Microsoft.Maui.ApplicationModel.AppInfo.Current.Name,
Microsoft.Maui.ApplicationModel.AppInfo.Current.BuildString,
Microsoft.Maui.ApplicationModel.AppInfo.Current.VersionString);
}
catch
{
return null;
}
}
}
}
20 changes: 17 additions & 3 deletions pkgs/sdk/client/src/PlatformSpecific/Connectivity.maui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@ namespace LaunchDarkly.Sdk.Client.PlatformSpecific
{
internal static partial class PlatformConnectivity
{
private static readonly bool _mauiAvailable;

static PlatformConnectivity()
{
Connectivity.Current.ConnectivityChanged += (sender, args) => ConnectivityChanged?.Invoke(sender, EventArgs.Empty);
try
{
Connectivity.Current.ConnectivityChanged += (sender, args) => ConnectivityChanged?.Invoke(sender, EventArgs.Empty);
_mauiAvailable = true;
}
catch
{
_mauiAvailable = false;
}
}

/// <summary>
/// Gets the current state of network access.
/// </summary>
public static LdNetworkAccess LdNetworkAccess => Convert(Connectivity.Current.NetworkAccess);
public static LdNetworkAccess LdNetworkAccess =>
_mauiAvailable ? Convert(Connectivity.Current.NetworkAccess) : LdNetworkAccess.Internet;

/// <summary>
/// Gets the active connectivity types for the device.
/// </summary>
public static IEnumerable<LdConnectionProfile> LdConnectionProfiles => Connectivity.Current.ConnectionProfiles.Distinct().Select(Convert);
public static IEnumerable<LdConnectionProfile> LdConnectionProfiles =>
_mauiAvailable
? Connectivity.Current.ConnectionProfiles.Distinct().Select(Convert)
: Enumerable.Empty<LdConnectionProfile>();

/// <summary>
/// Occurs when network access or profile has changed. This is just a signal and the
Expand Down
40 changes: 29 additions & 11 deletions pkgs/sdk/client/src/PlatformSpecific/DeviceInfo.maui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,36 @@ namespace LaunchDarkly.Sdk.Client.PlatformSpecific
{
internal static partial class DeviceInfo
{
internal static OsInfo? GetOsInfo() =>
new OsInfo(
PlatformToFamilyString(Devices.DeviceInfo.Current.Platform),
Devices.DeviceInfo.Current.Platform.ToString(),
Devices.DeviceInfo.Current.VersionString
);
internal static OsInfo? GetOsInfo()
{
try
{
return new OsInfo(
PlatformToFamilyString(Devices.DeviceInfo.Current.Platform),
Devices.DeviceInfo.Current.Platform.ToString(),
Devices.DeviceInfo.Current.VersionString
);
}
catch
{
return null;
}
}

internal static LaunchDarkly.Sdk.EnvReporting.LayerModels.DeviceInfo? GetDeviceInfo() =>
new EnvReporting.LayerModels.DeviceInfo(
Devices.DeviceInfo.Current.Manufacturer,
Devices.DeviceInfo.Current.Model
);
internal static LaunchDarkly.Sdk.EnvReporting.LayerModels.DeviceInfo? GetDeviceInfo()
{
try
{
return new EnvReporting.LayerModels.DeviceInfo(
Devices.DeviceInfo.Current.Manufacturer,
Devices.DeviceInfo.Current.Model
);
}
catch
{
return null;
}
}

private static string PlatformToFamilyString(Devices.DevicePlatform platform) {
if (platform == Devices.DevicePlatform.Android)
Expand Down
Loading