Skip to content

Commit

Permalink
fix: AnalyticsInfo and AnalyticsVersionInfo compatibility adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 20, 2021
1 parent fb8ba79 commit 4c4cd9a
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Windows.System.Profile
#endif
public static partial class AnalyticsInfo
{
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public static string DeviceForm
{
get
Expand All @@ -17,8 +17,8 @@ public static string DeviceForm
}
}
#endif
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public static global::Windows.System.Profile.AnalyticsVersionInfo VersionInfo
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.System.Profile
{
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
#endif
public partial class AnalyticsVersionInfo
{
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public string DeviceFamily
{
get
Expand All @@ -17,8 +17,8 @@ public string DeviceFamily
}
}
#endif
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public string DeviceFamilyVersion
{
get
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Android.Util;

using Uno.Extensions;
using Uno.System.Profile;
using Uno.Foundation.Logging;

namespace Windows.System.Profile
Expand Down
12 changes: 10 additions & 2 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
namespace Windows.System.Profile
{
/// <summary>
/// Provides version information about the device family.
/// </summary>
public static partial class AnalyticsInfo
{
#if __ANDROID__ || __IOS__ || __WASM__ || __MACOS__ || __SKIA__
/// <summary>
/// Gets the device form factor running the OS. For example,
/// the app could be running on a phone, tablet, desktop, and so on.
/// </summary>
public static string DeviceForm => GetDeviceForm().ToString();

/// <summary>
/// Gets version info about the device family.
/// </summary>
public static AnalyticsVersionInfo VersionInfo { get; } = new AnalyticsVersionInfo();
#endif
}
}
1 change: 1 addition & 0 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UIKit;
using Uno.System.Profile;

namespace Windows.System.Profile
{
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
using Uno.System.Profile;

namespace Windows.System.Profile
{
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.others.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if NET461 || __NETSTD_REFERENCE__
using Uno.System.Profile;

namespace Windows.System.Profile
{
public partial class AnalyticsInfo
{
private static UnoDeviceForm GetDeviceForm() => UnoDeviceForm.Desktop;
}
}
#endif
6 changes: 1 addition & 5 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using Uno.Foundation.Extensibility;
using Uno.System.Profile;

namespace Windows.System.Profile
{
Expand All @@ -21,9 +22,4 @@ public static partial class AnalyticsInfo

private static UnoDeviceForm GetDeviceForm() => _analyticsInfoExtension.Value?.GetDeviceForm() ?? UnoDeviceForm.Unknown;
}

internal interface IAnalyticsInfoExtension
{
UnoDeviceForm GetDeviceForm();
}
}
1 change: 1 addition & 0 deletions src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Uno.Foundation;
using Uno.System.Profile;

namespace Windows.System.Profile
{
Expand Down
10 changes: 3 additions & 7 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.Android.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#if __ANDROID__
using Android.OS;

namespace Windows.System.Profile
Expand All @@ -7,13 +6,10 @@ public partial class AnalyticsVersionInfo
{
private const string OsName = "Android";

internal AnalyticsVersionInfo()
partial void Initialize()
{
DeviceFamily = $"{OsName}.{AnalyticsInfo.DeviceForm}";
DeviceFamilyVersion = Build.VERSION.Release;
}

public string DeviceFamily => OsName + '.' + AnalyticsInfo.DeviceForm;

public string DeviceFamilyVersion => Build.VERSION.Release;
}
}
#endif
29 changes: 29 additions & 0 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Uno;

namespace Windows.System.Profile
{
/// <summary>
/// Provides version information about the device family.
/// </summary>
public partial class AnalyticsVersionInfo
{
public AnalyticsVersionInfo() => Initialize();

partial void Initialize();

/// <summary>
/// Gets a string that represents the type of device the application is running on.
/// </summary>
public string DeviceFamily { get; private set; } = $"{Environment.OSVersion.Platform}.Desktop";

/// <summary>
/// Gets the version within the device family.
/// </summary>
/// <remarks>
/// Needs to be parsable long number.
/// </remarks>
[NotImplemented("__WASM__")]
public string DeviceFamilyVersion { get; private set; } = "0";
}
}
12 changes: 3 additions & 9 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#if __IOS__
using UIKit;

namespace Windows.System.Profile
{
public partial class AnalyticsVersionInfo
{
private const string OsName = "iOS";

internal AnalyticsVersionInfo()
partial void Initialize()
{
DeviceFamily = $"{OsName}.{AnalyticsInfo.DeviceForm}";
DeviceFamilyVersion = UIDevice.CurrentDevice.SystemVersion;
}

public string DeviceFamily => OsName + '.' + AnalyticsInfo.DeviceForm;

public string DeviceFamilyVersion => UIDevice.CurrentDevice.SystemVersion;
}
}
#endif
6 changes: 3 additions & 3 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.macOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#if __MACOS__
using AppKit;
using Foundation;

Expand All @@ -8,13 +7,14 @@ public partial class AnalyticsVersionInfo
{
private const string OsName = "macOS";

internal AnalyticsVersionInfo()
partial void Initialize()
{
DeviceFamily = $"{OsName}.{AnalyticsInfo.DeviceForm}";
DeviceFamilyVersion = UIDevice.CurrentDevice.SystemVersion;
}

public string DeviceFamily => OsName + '.' + AnalyticsInfo.DeviceForm;

public string DeviceFamilyVersion => NSProcessInfo.ProcessInfo.OperatingSystemVersionString;
}
}
#endif
9 changes: 4 additions & 5 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ namespace Windows.System.Profile
{
public partial class AnalyticsVersionInfo
{
internal AnalyticsVersionInfo()
{
}

public string DeviceFamily => Environment.OSVersion.Platform.ToString();

public string DeviceFamilyVersion => Environment.OSVersion.VersionString;
partial void Initialize()
{
DeviceFamily = $"{Environment.OSVersion.Platform.ToString()}.{AnalyticsInfo.DeviceForm}";
}
}
}
24 changes: 5 additions & 19 deletions src/Uno.UWP/System/Profile/AnalyticsVersionInfo.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Uno;
using static Uno.Foundation.WebAssemblyRuntime;

namespace Windows.System.Profile
{
public partial class AnalyticsVersionInfo
{
private const string OsName = "Browser";
private const string BrowserVersionFallback = "Unknown";
private const string JsType = "Windows.System.Profile.AnalyticsVersionInfo";

internal AnalyticsVersionInfo()
{
}

public string DeviceFamily => OsName + '.' + AnalyticsInfo.DeviceForm;

public string DeviceFamilyVersion => GetUserAgent();

private string GetUserAgent()
{
var userAgent = InvokeJS(JsType + ".getUserAgent()");
if (!string.IsNullOrEmpty(userAgent))
{
return userAgent;
}
return BrowserVersionFallback;
}
partial void Initialize()
{
DeviceFamily = $"{OsName}.{AnalyticsInfo.DeviceForm}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#nullable enable

using Uno.System.Profile;

namespace Windows.System.Profile.Internal
{
internal interface IAnalyticsInfoExtension
{
UnoDeviceForm GetDeviceForm();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#nullable enable

namespace Uno.System.Profile
{
internal interface IAnalyticsVersionInfoExtension
{

}
}
4 changes: 3 additions & 1 deletion src/Uno.UWP/System/Profile/Internal/UnoDeviceForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Windows.System.Profile
#nullable enable

namespace Uno.System.Profile
{
internal enum UnoDeviceForm
{
Expand Down

0 comments on commit 4c4cd9a

Please sign in to comment.