mirror of https://github.com/2dust/v2rayN
Fix some code
parent
0da9cb45bd
commit
5a7836115e
|
@ -105,7 +105,7 @@ namespace ServiceLib.Services
|
|||
{
|
||||
try
|
||||
{
|
||||
var result1 = await DownloadStringAsync(url, blProxy, userAgent);
|
||||
var result1 = await DownloadStringAsync(url, blProxy, userAgent, 15);
|
||||
if (Utils.IsNotEmpty(result1))
|
||||
{
|
||||
return result1;
|
||||
|
@ -123,7 +123,7 @@ namespace ServiceLib.Services
|
|||
|
||||
try
|
||||
{
|
||||
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent);
|
||||
var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent, 15);
|
||||
if (Utils.IsNotEmpty(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;
|
||||
}
|
||||
|
||||
|
@ -166,7 +146,7 @@ namespace ServiceLib.Services
|
|||
/// DownloadString
|
||||
/// </summary>
|
||||
/// <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
|
||||
{
|
||||
|
@ -192,7 +172,7 @@ namespace ServiceLib.Services
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -211,7 +191,7 @@ namespace ServiceLib.Services
|
|||
/// DownloadString
|
||||
/// </summary>
|
||||
/// <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
|
||||
{
|
||||
|
@ -223,7 +203,7 @@ namespace ServiceLib.Services
|
|||
{
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -40,25 +40,7 @@ namespace v2rayN.Desktop.Common
|
|||
|
||||
public static WindowIcon GetAppIcon(ESysProxyType sysProxyType)
|
||||
{
|
||||
int index = 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 index = (int)sysProxyType + 1;
|
||||
var uri = new Uri($"avares://{Assembly.GetExecutingAssembly().GetName().Name}/Assets/NotifyIcon{index}.ico");
|
||||
using var bitmap = new Bitmap(AssetLoader.Open(uri));
|
||||
return new(bitmap);
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace v2rayN.Handler
|
|||
{
|
||||
try
|
||||
{
|
||||
int index = (int)config.systemProxyItem.sysProxyType;
|
||||
var index = (int)config.systemProxyItem.sysProxyType;
|
||||
|
||||
//Load from routing setting
|
||||
var createdIcon = await GetNotifyIcon4Routing(config);
|
||||
|
@ -46,25 +46,7 @@ namespace v2rayN.Handler
|
|||
|
||||
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
||||
{
|
||||
int index = 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;
|
||||
}
|
||||
var index = (int)config.systemProxyItem.sysProxyType + 1;
|
||||
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue