-
Notifications
You must be signed in to change notification settings - Fork 746
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
feat: Platform runtime helper #18758
Open
mcNets
wants to merge
10
commits into
unoplatform:master
Choose a base branch
from
mcNets:platform-runtime-helper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e5f103
feat: Added PlatformRuntimeHelper to get the current target at runtime.
mcNets c8339d7
feat: Added a RuntimeHelper to Toolkit
mcNets f36c6d4
fix: Added WinUI specific enums
mcNets cc211ac
fix: Some errors pointed out in conversation.
mcNets d2e9277
fix: Typo fixed.
mcNets b987d2e
fix: PlatformRuntimeHelper must be public.,
mcNets 9e08db8
fix: Same name in Uno.UI.Helper and Uno.UI.Toolkit
mcNets f1cf07b
fix: WPF points to SkiaWpfIslands, default to Unknown
mcNets e2675e1
feat: Added runtime tests to check platform detection.
mcNets 6a0eb4f
fix: Removed MacOS from runtimes list
mcNets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/Uno.UI.RuntimeTests/Tests/Uno_UI_Toolkit/Given_RuntimePlatformDetected.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Private.Infrastructure; | ||
using Uno.Disposables; | ||
using Uno.UI.RuntimeTests.Extensions; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using Uno.UI.Toolkit; | ||
using Uno.UI.Helpers; | ||
using Windows.UI; | ||
using Windows.UI.ViewManagement; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Shapes; | ||
using static Private.Infrastructure.TestServices; | ||
using FluentAssertions; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Uno_UI_Toolkit | ||
{ | ||
[TestClass] | ||
[RunsOnUIThread] | ||
public class Given_RuntimePlatformDetected | ||
{ | ||
#if __SKIA__ | ||
[TestMethod] | ||
public void When_IsSkia() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsSkia().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __IOS__ | ||
[TestMethod] | ||
public void When_IsIOS() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsIOS().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __ANDROID__ | ||
[TestMethod] | ||
public void When_IsAndroid() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsAndroid().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __MACCATALYST__ | ||
[TestMethod] | ||
public void When_IsMacCatalyst() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsMacCatalyst().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if __WASM__ | ||
[TestMethod] | ||
public void When_IsWebAssembly() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.IsWebAssembly().Should().BeTrue(); | ||
} | ||
#endif | ||
|
||
#if !HAS_UNO | ||
[TestMethod] | ||
public void When_IsWindows() | ||
{ | ||
Uno.UI.Toolkit.PlatformRuntimeHelper.Current.Should().Be(Uno.UI.Toolkit.UnoRuntimePlatform.Windows); | ||
} | ||
#else | ||
[TestMethod] | ||
public void When_IsUnoIsKnown() | ||
{ | ||
Uno.UI.Helpers.PlatformRuntimeHelper.Current.Should().NotBe(Uno.UI.Toolkit.UnoRuntimePlatform.Unknown); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Uno.UI.Helpers; | ||
|
||
namespace Uno.UI.Toolkit; | ||
|
||
public static class PlatformRuntimeHelper | ||
{ | ||
public static UnoRuntimePlatform Current => | ||
#if !HAS_UNO | ||
Uno.UI.Toolkit.UnoRuntimePlatform.Windows; | ||
#else | ||
(Uno.UI.Toolkit.UnoRuntimePlatform)PlatformRuntimeHelper.Current; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Uno.UI.Toolkit; | ||
|
||
public enum UnoRuntimePlatform | ||
{ | ||
Unknown, | ||
Android, | ||
iOS, | ||
MacCatalyst, | ||
WebAssembly, | ||
Windows, | ||
SkiaGtk, | ||
SkiaWpfIslands, | ||
SkiaX11, | ||
SkiaFrameBuffer, | ||
SkiaMacOS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.UI.Helpers; | ||
|
||
public static class PlatformRuntimeHelper | ||
{ | ||
internal static UnoRuntimePlatform SkiaPlatform { get; set; } = UnoRuntimePlatform.Unknown; | ||
|
||
public static UnoRuntimePlatform Current => GetPlatform(); | ||
|
||
private static UnoRuntimePlatform GetPlatform() => | ||
#if __ANDROID__ | ||
UnoRuntimePlatform.Android; | ||
#elif __IOS__ | ||
UnoRuntimePlatform.iOS; | ||
#elif __MACCATALYST__ | ||
UnoRuntimePlatform.MacCatalyst; | ||
#elif __WASM__ | ||
UnoRuntimePlatform.WebAssembly; | ||
#elif __SKIA__ | ||
SkiaPlatform; | ||
#else | ||
UnoRuntimePlatform.Unknown; | ||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.UI.Helpers; | ||
|
||
public enum UnoRuntimePlatform | ||
{ | ||
Unknown, | ||
Android, | ||
iOS, | ||
MacCatalyst, | ||
WebAssembly, | ||
Windows, | ||
SkiaGtk, | ||
SkiaWpfIslands, | ||
SkiaX11, | ||
SkiaFrameBuffer, | ||
SkiaMacOS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Uno.UI.Helpers; | ||
|
||
public static class UnoRuntimePlatformExtensions | ||
{ | ||
public static bool IsSkia(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.SkiaFrameBuffer | ||
|| platform == UnoRuntimePlatform.SkiaGtk | ||
|| platform == UnoRuntimePlatform.SkiaMacOS | ||
|| platform == UnoRuntimePlatform.SkiaWpfIslands | ||
|| platform == UnoRuntimePlatform.SkiaX11; | ||
|
||
public static bool IsIOS(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.iOS; | ||
|
||
public static bool IsMacCatalyst(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.MacCatalyst; | ||
|
||
public static bool IsWebAssembly(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.WebAssembly; | ||
|
||
public static bool IsWindows(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.Windows; | ||
|
||
public static bool IsAndroid(this UnoRuntimePlatform platform) => platform == UnoRuntimePlatform.Android; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a runtime test that gets the value from
GetPlatform()
at runtime and checks that the result is notUnknown
- this will future proof us against potential new platforms being added and us forgetting to update this code path