Commit 39d351dc authored by justcoding121's avatar justcoding121

fix operating system checks

parent c7a1ff75
using System; using System;
using System.Runtime.InteropServices;
using Titanium.Web.Proxy.Examples.Basic.Helpers; using Titanium.Web.Proxy.Examples.Basic.Helpers;
using Titanium.Web.Proxy.Helpers;
namespace Titanium.Web.Proxy.Examples.Basic namespace Titanium.Web.Proxy.Examples.Basic
{ {
...@@ -10,7 +10,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -10,7 +10,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
public static void Main(string[] args) 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(); ConsoleHelper.DisableQuickEditMode();
......
...@@ -10,7 +10,6 @@ using Titanium.Web.Proxy.Exceptions; ...@@ -10,7 +10,6 @@ using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Examples.Basic namespace Titanium.Web.Proxy.Examples.Basic
{ {
...@@ -109,12 +108,11 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -109,12 +108,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
endPoint.IpAddress, endPoint.Port); endPoint.IpAddress, endPoint.Port);
} }
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Only explicit proxies can be set as system proxy! // Only explicit proxies can be set as system proxy!
//proxyServer.SetAsSystemHttpProxy(explicitEndPoint); //proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
//proxyServer.SetAsSystemHttpsProxy(explicitEndPoint); //proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
if(RunTime.IsWindows)
{
proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp); proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
} }
} }
......
using System; using System;
#if NETSTANDARD2_0
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#endif
namespace Titanium.Web.Proxy.Helpers namespace Titanium.Web.Proxy.Helpers
{ {
/// <summary> /// <summary>
/// Run time helpers /// Run time helpers
/// </summary> /// </summary>
internal class RunTime public static class RunTime
{ {
/// <summary> /// <summary>
/// cache for mono runtime check /// cache for mono runtime check
...@@ -14,6 +16,19 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -14,6 +16,19 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns> /// <returns></returns>
private static readonly Lazy<bool> isRunningOnMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null); 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> /// <summary>
/// cache for Windows platform check /// cache for Windows platform check
/// </summary> /// </summary>
...@@ -21,17 +36,29 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -21,17 +36,29 @@ namespace Titanium.Web.Proxy.Helpers
private static bool isRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private static bool isRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static bool isRunningOnLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); private static bool isRunningOnLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
private static bool isRunningOnMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); private static bool isRunningOnMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#endif
/// <summary> /// <summary>
/// Is running on Mono? /// Is running on Mono?
/// </summary> /// </summary>
internal static bool IsRunningOnMono => isRunningOnMono.Value; 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