Commit 39d351dc authored by justcoding121's avatar justcoding121

fix operating system checks

parent c7a1ff75
using System;
using System.Runtime.InteropServices;
using Titanium.Web.Proxy.Examples.Basic.Helpers;
using Titanium.Web.Proxy.Helpers;
namespace Titanium.Web.Proxy.Examples.Basic
{
......@@ -10,9 +10,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
public static void Main(string[] args)
{
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (RunTime.IsWindows)
{
// fix console hang due to QuickEdit mode
// fix console hang due to QuickEdit mode
ConsoleHelper.DisableQuickEditMode();
}
......
......@@ -10,7 +10,6 @@ using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Examples.Basic
{
......@@ -109,12 +108,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
endPoint.IpAddress, endPoint.Port);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// Only explicit proxies can be set as system proxy!
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
if(RunTime.IsWindows)
{
// Only explicit proxies can be set as system proxy!
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
}
}
......
using System;
#if NETSTANDARD2_0
using System.Runtime.InteropServices;
#endif
namespace Titanium.Web.Proxy.Helpers
{
/// <summary>
/// Run time helpers
/// </summary>
internal class RunTime
public static class RunTime
{
/// <summary>
/// cache for mono runtime check
......@@ -14,6 +16,19 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
private static readonly Lazy<bool> isRunningOnMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
/// <summary>
/// cache for mono runtime check
/// </summary>
/// <returns></returns>
private static readonly Lazy<bool> isRunningOnMonoLinux = new Lazy<bool>(() => IsRunningOnMono && (int)Environment.OSVersion.Platform == 4);
/// <summary>
/// cache for mono runtime check
/// </summary>
/// <returns></returns>
private static readonly Lazy<bool> isRunningOnMonoMac = new Lazy<bool>(() => IsRunningOnMono && (int)Environment.OSVersion.Platform == 6);
#if NETSTANDARD2_0
/// <summary>
/// cache for Windows platform check
/// </summary>
......@@ -21,17 +36,29 @@ namespace Titanium.Web.Proxy.Helpers
private static bool isRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static bool isRunningOnLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
private static bool isRunningOnMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
/// <summary>
/// Is running on Mono?
/// </summary>
internal static bool IsRunningOnMono => isRunningOnMono.Value;
internal static bool IsLinux => isRunningOnLinux;
#if NETSTANDARD2_0
public static bool IsLinux => isRunningOnLinux;
#else
public static bool IsLinux => isRunningOnMonoLinux.Value;
#endif
internal static bool IsWindows => isRunningOnWindows;
#if NETSTANDARD2_0
public static bool IsWindows => isRunningOnWindows;
#else
public static bool IsWindows => !IsLinux && !IsMac;
#endif
internal static bool IsMac => isRunningOnMac;
#if NETSTANDARD2_0
public static bool IsMac => isRunningOnMac;
#else
public static bool IsMac => isRunningOnMonoMac.Value;
#endif
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment