Commit 8311e6b5 authored by justcoding121's avatar justcoding121

#522 fix Uwp startup

parent 2a57f752
using System;
using System.Runtime.InteropServices;
using System.Text;
#if NETSTANDARD2_0
using System.Runtime.InteropServices;
#endif
......@@ -53,6 +55,7 @@ namespace Titanium.Web.Proxy.Helpers
#else
public static bool IsWindows => !IsLinux && !IsMac;
#endif
public static bool IsUwpOnWindows => IsWindows && UwpHelper.IsRunningAsUwp();
#if NETSTANDARD2_0
public static bool IsMac => isRunningOnMac;
......@@ -60,5 +63,43 @@ namespace Titanium.Web.Proxy.Helpers
public static bool IsMac => isRunningOnMonoMac.Value;
#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
ProxyEndPoints = new List<ProxyEndPoint>();
tcpConnectionFactory = new TcpConnectionFactory(this);
if (!RunTime.IsRunningOnMono && RunTime.IsWindows)
if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
{
systemProxySettingsManager = new SystemProxyManager();
}
......@@ -542,7 +542,7 @@ namespace Titanium.Web.Proxy
// clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
// 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();
if (proxyInfo.Proxies != null)
......@@ -593,7 +593,7 @@ namespace Titanium.Web.Proxy
throw new Exception("Proxy is not running.");
}
if (!RunTime.IsRunningOnMono && RunTime.IsWindows)
if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
{
bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>()
.Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
......
......@@ -25,7 +25,6 @@ namespace Titanium.Web.Proxy
/// </summary>
public partial class ProxyServer
{
private bool isWindowsAuthenticationEnabledAndSupported =>
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