Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull iOS / android platform detection methods locally to avoid potential usage before ready #5385

Merged
merged 1 commit into from
Sep 1, 2022
Merged
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
8 changes: 6 additions & 2 deletions osu.Framework/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -40,9 +41,9 @@ static RuntimeInfo()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
OS = Platform.Windows;
if (osuTK.Configuration.RunningOnIOS)
if (detectIOS())
OS = OS == 0 ? Platform.iOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.iOS)}, but is already {Enum.GetName(typeof(Platform), OS)}");
if (osuTK.Configuration.RunningOnAndroid)
if (detectAndroid())
OS = OS == 0 ? Platform.Android : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.Android)}, but is already {Enum.GetName(typeof(Platform), OS)}");
if (OS != Platform.iOS && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
OS = OS == 0 ? Platform.macOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.macOS)}, but is already {Enum.GetName(typeof(Platform), OS)}");
Expand All @@ -53,6 +54,9 @@ static RuntimeInfo()
throw new PlatformNotSupportedException("Operating system could not be detected correctly.");
}

private static bool detectAndroid() => AppDomain.CurrentDomain.GetAssemblies().Any(x => x.ToString().Contains("Mono.Android"));
private static bool detectIOS() => AppDomain.CurrentDomain.GetAssemblies().Any(x => x.ToString().Contains("Xamarin.iOS"));

public enum Platform
{
Windows = 1,
Expand Down