Browse Source

Extend StandardRuntimePlatform with more apple platforms

pull/14196/head
Max Katz 2 years ago
parent
commit
1aa1f0f736
  1. 12
      src/Avalonia.Base/Compatibility/OperatingSystem.cs
  2. 14
      src/Avalonia.Base/Platform/StandardRuntimePlatform.cs

12
src/Avalonia.Base/Compatibility/OperatingSystem.cs

@ -8,7 +8,9 @@ namespace Avalonia.Compatibility
#if NET6_0_OR_GREATER
public static bool IsWindows() => OperatingSystem.IsWindows();
public static bool IsMacOS() => OperatingSystem.IsMacOS();
public static bool IsMacCatalyst() => OperatingSystem.IsMacCatalyst();
public static bool IsLinux() => OperatingSystem.IsLinux();
public static bool IsFreeBSD() => OperatingSystem.IsFreeBSD();
public static bool IsAndroid() => OperatingSystem.IsAndroid();
public static bool IsIOS() => OperatingSystem.IsIOS();
public static bool IsTvOS() => OperatingSystem.IsTvOS();
@ -18,10 +20,12 @@ namespace Avalonia.Compatibility
public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public static bool IsAndroid() => IsOSPlatform("ANDROID");
public static bool IsIOS() => IsOSPlatform("IOS");
public static bool IsTvOS() => IsOSPlatform("TVOS"); // untested
public static bool IsBrowser() => IsOSPlatform("BROWSER");
public static bool IsFreeBSD() => false;
public static bool IsAndroid() => false;
public static bool IsIOS() => false;
public static bool IsMacCatalyst() => false;
public static bool IsTvOS() => false;
public static bool IsBrowser() => false;
public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform));
#endif
}

14
src/Avalonia.Base/Platform/StandardRuntimePlatform.cs

@ -1,20 +1,18 @@
using System;
using System.Threading;
using Avalonia.Compatibility;
using Avalonia.Metadata;
using Avalonia.Platform.Internal;
namespace Avalonia.Platform
{
[PrivateApi]
public class StandardRuntimePlatform : IRuntimePlatform
{
private static readonly RuntimePlatformInfo s_info = new()
public virtual RuntimePlatformInfo GetRuntimeInfo() => new()
{
IsDesktop = OperatingSystemEx.IsWindows() || OperatingSystemEx.IsMacOS() || OperatingSystemEx.IsLinux(),
IsMobile = OperatingSystemEx.IsAndroid() || OperatingSystemEx.IsIOS()
IsDesktop = OperatingSystemEx.IsWindows()
|| OperatingSystemEx.IsMacOS() || OperatingSystemEx.IsMacCatalyst()
|| OperatingSystemEx.IsLinux() || OperatingSystemEx.IsFreeBSD(),
IsMobile = OperatingSystemEx.IsAndroid() || (OperatingSystemEx.IsIOS() && !OperatingSystemEx.IsMacCatalyst()),
IsTV = OperatingSystemEx.IsTvOS()
};
public virtual RuntimePlatformInfo GetRuntimeInfo() => s_info;
}
}

Loading…
Cancel
Save