Skip to content

Commit

Permalink
Merge pull request unoplatform#15426 from Youssef1313/os-checks
Browse files Browse the repository at this point in the history
refactor: Simplify OS checks
  • Loading branch information
jeromelaban authored Feb 10, 2024
2 parents 0c8b4c5 + 13462f0 commit 2723190
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/AddIns/Uno.UI.MediaPlayer.Skia.Gtk/VideoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Native
/// </summary>
public VideoView()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (OperatingSystem.IsLinux())
{
#pragma warning disable CA1806 // Do not ignore method results
Native.XInitThreads();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static SampleControlUITestBase()
private static void TryInitializeSkiaSharpLoader()
{
if (AppInitializer.GetLocalPlatform() == Platform.Browser
&& !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
&& !OperatingSystem.IsWindows())
{
#if DEBUG
Console.WriteLine("Initializing SkiaSharp loader");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class ProcessHelper
{
public static (int exitCode, string output, string error) RunProcess(string executable, string parameters, string? workingDirectory = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
if (!OperatingSystem.IsWindows()
&& executable.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
{
executable = Path.GetFileNameWithoutExtension(executable);
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Runtime.Skia.Gtk/GtkHost.HarfbuzzPreload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class GtkHost : ISkiaApplicationHost
{
private void PreloadHarfBuzz()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (OperatingSystem.IsLinux())
{
// Here, we preload libHarfBuzzSharp.so using the RTLD_DEEPBIND flag, so that
// is loaded with its static dependencies, and not the ones from the system, particularly
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Runtime.Skia.Gtk/Helpers/Dpi/DpiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal float GetNativeDpi()
}

float dpi;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
dpi = DpiUtilities.GetDpiForWindow(DpiUtilities.GetWin32Hwnd(GetWindow().Window));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal GtkSystemThemeHelperExtension(object owner)

private void ObserveSystemTheme()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}
Expand All @@ -37,7 +37,7 @@ private void ObserveSystemTheme()

private void UnobserveSystemTheme()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ private bool IsGtkThemeDark(string themeName)

public SystemTheme GetSystemTheme()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
return GetWindowsTheme();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void OnKeyReleaseEvent(EventKey evt)

private static char? KeyCodeToUnicode(uint keyCode, uint keyVal)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
var result = InputHelper.WindowsKeyCodeToUnicode(keyCode);
return result.Length > 0 ? result[0] : null; // TODO: supplementary code points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static bool IsSupported
get
{
// OpenGL support on macOS is currently broken
var isMacOS = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
var isMacOS = OperatingSystem.IsMacOS();

// WSL2 is not supported because of a low version for GLSL (https://github.com/unoplatform/uno/issues/8643#issuecomment-1114392827)
var isWSL2 = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
var isWSL2 = OperatingSystem.IsLinux()
// https://github.com/microsoft/WSL/issues/423#issuecomment-844418910
&& File.Exists("/proc/sys/kernel/osrelease")
&& File.ReadAllText("/proc/sys/kernel/osrelease").Trim().EndsWith("WSL2", StringComparison.Ordinal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static bool IsSupported
get
{
// OpenGL support on macOS is currently broken
var isMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
var isMacOs = OperatingSystem.IsMacOS();

try
{
Expand Down
14 changes: 7 additions & 7 deletions src/Uno.UI.Runtime.Skia.Gtk/Rendering/SoftwareRenderSurface.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#nullable enable

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Cairo;
using SkiaSharp;
using Gtk;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Input;
using WUX = Microsoft.UI.Xaml;
using SkiaSharp;
using Uno.Foundation.Logging;
using System.Diagnostics;
using Windows.Graphics.Display;
using Gtk;
using Uno.UI.Hosting;
using Microsoft.UI.Composition;
using Windows.Graphics.Display;

namespace Uno.UI.Runtime.Skia.Gtk;

Expand Down Expand Up @@ -40,7 +40,7 @@ public SoftwareRenderSurface(IXamlRootHost host)

_colorType = SKImageInfo.PlatformColorType;
// R and B channels are inverted on macOS running on arm64 CPU and this is not detected by Skia
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ProgressBarTest
[TestMethod]
public async Task ProgressBarLayoutUpdate()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (OperatingSystem.IsMacOS())
{
Assert.Inconclusive("This test is not valid on macOS");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/Helpers/InputHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static string InputToUnicode(uint keyCode, uint scanCode)

public static bool TryConvertKeyCodeToScanCode(uint keyCode, out uint scanCode)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (OperatingSystem.IsWindows())
{
scanCode = MapVirtualKey(keyCode, 0);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Storage/ApplicationData.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private string GetLocalCacheFolderRootPath()
return path;
}

string? localCacheRootFolder = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
string? localCacheRootFolder = OperatingSystem.IsLinux() ?
Environment.GetEnvironmentVariable("XDG_CACHE_HOME") :
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWPSyncGenerator/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ProcessHelper
{
public static (int exitCode, string output, string error) RunProcess(string executable, string parameters, string? workingDirectory = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
if (!OperatingSystem.IsWindows()
&& executable.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
{
executable = Path.GetFileNameWithoutExtension(executable);
Expand Down

0 comments on commit 2723190

Please sign in to comment.