Commit 8311e6b5 authored by justcoding121's avatar justcoding121

#522 fix Uwp startup

parent 2a57f752
using System; using System;
using System.Runtime.InteropServices;
using System.Text;
#if NETSTANDARD2_0 #if NETSTANDARD2_0
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#endif #endif
...@@ -53,6 +55,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -53,6 +55,7 @@ namespace Titanium.Web.Proxy.Helpers
#else #else
public static bool IsWindows => !IsLinux && !IsMac; public static bool IsWindows => !IsLinux && !IsMac;
#endif #endif
public static bool IsUwpOnWindows => IsWindows && UwpHelper.IsRunningAsUwp();
#if NETSTANDARD2_0 #if NETSTANDARD2_0
public static bool IsMac => isRunningOnMac; public static bool IsMac => isRunningOnMac;
...@@ -60,5 +63,43 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -60,5 +63,43 @@ namespace Titanium.Web.Proxy.Helpers
public static bool IsMac => isRunningOnMonoMac.Value; public static bool IsMac => isRunningOnMonoMac.Value;
#endif #endif
//https://github.com/qmatteoq/DesktopBridgeHelpers/blob/master/DesktopBridge.Helpers/Helpers.cs
private class UwpHelper
{
const long APPMODEL_ERROR_NO_PACKAGE = 15700L;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName);
internal static bool IsRunningAsUwp()
{
if (IsWindows7OrLower)
{
return false;
}
else
{
int length = 0;
var sb = new StringBuilder(0);
int result = GetCurrentPackageFullName(ref length, sb);
sb = new StringBuilder(length);
result = GetCurrentPackageFullName(ref length, sb);
return result != APPMODEL_ERROR_NO_PACKAGE;
}
}
private static bool IsWindows7OrLower
{
get
{
int versionMajor = Environment.OSVersion.Version.Major;
int versionMinor = Environment.OSVersion.Version.Minor;
double version = versionMajor + (double)versionMinor / 10;
return version <= 6.1;
}
}
}
} }
} }
...@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy ...@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints = new List<ProxyEndPoint>(); ProxyEndPoints = new List<ProxyEndPoint>();
tcpConnectionFactory = new TcpConnectionFactory(this); tcpConnectionFactory = new TcpConnectionFactory(this);
if (!RunTime.IsRunningOnMono && RunTime.IsWindows) if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
{ {
systemProxySettingsManager = new SystemProxyManager(); systemProxySettingsManager = new SystemProxyManager();
} }
...@@ -542,7 +542,7 @@ namespace Titanium.Web.Proxy ...@@ -542,7 +542,7 @@ namespace Titanium.Web.Proxy
// clear any system proxy settings which is pointing to our own endpoint (causing a cycle) // clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
// due to ungracious proxy shutdown before or something else // due to ungracious proxy shutdown before or something else
if (systemProxySettingsManager != null && RunTime.IsWindows) if (systemProxySettingsManager != null && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
{ {
var proxyInfo = systemProxySettingsManager.GetProxyInfoFromRegistry(); var proxyInfo = systemProxySettingsManager.GetProxyInfoFromRegistry();
if (proxyInfo.Proxies != null) if (proxyInfo.Proxies != null)
...@@ -593,7 +593,7 @@ namespace Titanium.Web.Proxy ...@@ -593,7 +593,7 @@ namespace Titanium.Web.Proxy
throw new Exception("Proxy is not running."); throw new Exception("Proxy is not running.");
} }
if (!RunTime.IsRunningOnMono && RunTime.IsWindows) if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
{ {
bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>() bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>()
.Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy); .Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
......
...@@ -25,7 +25,6 @@ namespace Titanium.Web.Proxy ...@@ -25,7 +25,6 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public partial class ProxyServer public partial class ProxyServer
{ {
private bool isWindowsAuthenticationEnabledAndSupported => private bool isWindowsAuthenticationEnabledAndSupported =>
EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono; EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono;
......
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