mirror of https://github.com/2dust/v2rayN
Fix some code
parent
0da9cb45bd
commit
5a7836115e
|
@ -105,7 +105,7 @@ namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result1 = await DownloadStringAsync(url, blProxy, userAgent);
|
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
|
||||||
if (Utils.IsNotEmpty(result1))
|
if (Utils.IsNotEmpty(result1))
|
||||||
{
|
{
|
||||||
return result1;
|
return result1;
|
||||||
|
@ -123,7 +123,7 @@ namespace ServiceLib.Services
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent);
|
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
|
||||||
if (Utils.IsNotEmpty(result2))
|
if (Utils.IsNotEmpty(result2))
|
||||||
{
|
{
|
||||||
return result2;
|
return result2;
|
||||||
|
@ -139,26 +139,6 @@ namespace ServiceLib.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var wc = new WebClient();
|
|
||||||
wc.Proxy = GetWebProxy(blProxy);
|
|
||||||
var result3 = await wc.DownloadStringTaskAsync(url);
|
|
||||||
if (Utils.IsNotEmpty(result3))
|
|
||||||
{
|
|
||||||
return result3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logging.SaveLog(ex.Message, ex);
|
|
||||||
Error?.Invoke(this, new ErrorEventArgs(ex));
|
|
||||||
if (ex.InnerException != null)
|
|
||||||
{
|
|
||||||
Error?.Invoke(this, new ErrorEventArgs(ex.InnerException));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +146,7 @@ namespace ServiceLib.Services
|
||||||
/// DownloadString
|
/// DownloadString
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public async Task<string?> DownloadStringAsync(string url, bool blProxy, string userAgent)
|
private async Task<string?> DownloadStringAsync(string url, bool blProxy, string userAgent, int timeout)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -192,7 +172,7 @@ namespace ServiceLib.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
var result = await HttpClientHelper.Instance.GetAsync(client, url, cts.Token).WaitAsync(TimeSpan.FromSeconds(30), cts.Token);
|
var result = await HttpClientHelper.Instance.GetAsync(client, url, cts.Token).WaitAsync(TimeSpan.FromSeconds(timeout), cts.Token);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -211,7 +191,7 @@ namespace ServiceLib.Services
|
||||||
/// DownloadString
|
/// DownloadString
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public async Task<string?> DownloadStringViaDownloader(string url, bool blProxy, string userAgent)
|
private async Task<string?> DownloadStringViaDownloader(string url, bool blProxy, string userAgent, int timeout)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -223,7 +203,7 @@ namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
userAgent = Utils.GetVersion(false);
|
userAgent = Utils.GetVersion(false);
|
||||||
}
|
}
|
||||||
var result = await DownloaderHelper.Instance.DownloadStringAsync(webProxy, url, userAgent, 30);
|
var result = await DownloaderHelper.Instance.DownloadStringAsync(webProxy, url, userAgent, timeout);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -40,25 +40,7 @@ namespace v2rayN.Desktop.Common
|
||||||
|
|
||||||
public static WindowIcon GetAppIcon(ESysProxyType sysProxyType)
|
public static WindowIcon GetAppIcon(ESysProxyType sysProxyType)
|
||||||
{
|
{
|
||||||
int index = 1;
|
var index = (int)sysProxyType + 1;
|
||||||
switch (sysProxyType)
|
|
||||||
{
|
|
||||||
case ESysProxyType.ForcedClear:
|
|
||||||
index = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.ForcedChange:
|
|
||||||
index = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.Unchanged:
|
|
||||||
index = 3;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.Pac:
|
|
||||||
index = 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
var uri = new Uri($"avares://{Assembly.GetExecutingAssembly().GetName().Name}/Assets/NotifyIcon{index}.ico");
|
var uri = new Uri($"avares://{Assembly.GetExecutingAssembly().GetName().Name}/Assets/NotifyIcon{index}.ico");
|
||||||
using var bitmap = new Bitmap(AssetLoader.Open(uri));
|
using var bitmap = new Bitmap(AssetLoader.Open(uri));
|
||||||
return new(bitmap);
|
return new(bitmap);
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int index = (int)config.systemProxyItem.sysProxyType;
|
var index = (int)config.systemProxyItem.sysProxyType;
|
||||||
|
|
||||||
//Load from routing setting
|
//Load from routing setting
|
||||||
var createdIcon = await GetNotifyIcon4Routing(config);
|
var createdIcon = await GetNotifyIcon4Routing(config);
|
||||||
|
@ -46,29 +46,11 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
||||||
{
|
{
|
||||||
int index = 1;
|
var index = (int)config.systemProxyItem.sysProxyType + 1;
|
||||||
switch (config.systemProxyItem.sysProxyType)
|
|
||||||
{
|
|
||||||
case ESysProxyType.ForcedClear:
|
|
||||||
index = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.ForcedChange:
|
|
||||||
index = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.Unchanged:
|
|
||||||
index = 3;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ESysProxyType.Pac:
|
|
||||||
index = 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
|
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Icon?> GetNotifyIcon4Routing(Config config)
|
private async Task<Icon?> GetNotifyIcon4Routing(Config config)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue