Skip to content

Commit d376002

Browse files
committed
🎂 ForwardProxyView + HotkeysView + OnlineConfigView + VersionUpdatePromptView
- Infrastructure: use one HttpClient instance throughout the lifecycle - Version update: rewrite the update service and add update prompt window - Server sharing: add copy link button - Dependencies: add ReactiveUI.Events.WPF, ReactiveUI.Fody, ReactiveUI.Validation, WPFLocalizeExtension, MdXaml
1 parent a05a782 commit d376002

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3391
-2322
lines changed

‎shadowsocks-csharp/Controller/Service/GeositeUpdater.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public static class GeositeUpdater
3535

3636
private static readonly string DATABASE_PATH = Utils.GetTempPath("dlc.dat");
3737

38-
private static HttpClientHandler httpClientHandler;
39-
private static HttpClient httpClient;
4038
private static readonly string GEOSITE_URL = "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat";
4139
private static readonly string GEOSITE_SHA256SUM_URL = "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat.sha256sum";
4240
private static byte[] geositeDB;
@@ -82,30 +80,15 @@ public static async Task UpdatePACFromGeosite()
8280
SHA256 mySHA256 = SHA256.Create();
8381
var config = Program.MainController.GetCurrentConfiguration();
8482
bool blacklist = config.geositePreferDirect;
85-
83+
var httpClient = Program.MainController.GetHttpClient();
84+
8685
if (!string.IsNullOrWhiteSpace(config.geositeUrl))
8786
{
8887
logger.Info("Found custom Geosite URL in config file");
8988
geositeUrl = config.geositeUrl;
9089
}
9190
logger.Info($"Checking Geosite from {geositeUrl}");
9291

93-
// use System.Net.Http.HttpClient to download GeoSite db.
94-
// NASTY workaround: new HttpClient every update
95-
// because we can't change proxy on existing socketsHttpHandler instance
96-
httpClientHandler = new HttpClientHandler();
97-
httpClient = new HttpClient(httpClientHandler);
98-
if (!string.IsNullOrWhiteSpace(config.userAgentString))
99-
httpClient.DefaultRequestHeaders.Add("User-Agent", config.userAgentString);
100-
if (config.enabled)
101-
{
102-
httpClientHandler.Proxy = new WebProxy(
103-
config.isIPv6Enabled
104-
? $"[{IPAddress.IPv6Loopback}]"
105-
: IPAddress.Loopback.ToString(),
106-
config.localPort);
107-
}
108-
10992
try
11093
{
11194
// download checksum first
@@ -154,19 +137,6 @@ public static async Task UpdatePACFromGeosite()
154137
{
155138
Error?.Invoke(null, new ErrorEventArgs(ex));
156139
}
157-
finally
158-
{
159-
if (httpClientHandler != null)
160-
{
161-
httpClientHandler.Dispose();
162-
httpClientHandler = null;
163-
}
164-
if (httpClient != null)
165-
{
166-
httpClient.Dispose();
167-
httpClient = null;
168-
}
169-
}
170140
}
171141

172142
/// <summary>

‎shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,15 @@ namespace Shadowsocks.Controller.Service
1111
{
1212
public class OnlineConfigResolver
1313
{
14-
public static async Task<List<Server>> GetOnline(string url, string userAgentString, IWebProxy proxy = null)
14+
public static async Task<List<Server>> GetOnline(string url)
1515
{
16-
var httpClientHandler = new HttpClientHandler()
17-
{
18-
Proxy = proxy
19-
};
20-
var httpClient = new HttpClient(httpClientHandler)
21-
{
22-
Timeout = TimeSpan.FromSeconds(15)
23-
};
24-
if (!string.IsNullOrWhiteSpace(userAgentString))
25-
httpClient.DefaultRequestHeaders.Add("User-Agent", userAgentString);
26-
16+
var httpClient = Program.MainController.GetHttpClient();
2717
string server_json = await httpClient.GetStringAsync(url);
28-
2918
var servers = server_json.GetServers();
30-
3119
foreach (var server in servers)
3220
{
3321
server.group = url;
3422
}
35-
3623
return servers.ToList();
3724
}
3825
}

‎shadowsocks-csharp/Controller/Service/TCPRelay.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public AsyncSession(AsyncSession session, T state) : base(session.Remote)
191191
public DateTime lastActivity;
192192

193193
private readonly ShadowsocksController _controller;
194-
private readonly ProxyConfig _config;
194+
private readonly ForwardProxyConfig _config;
195195
private readonly Socket _connection;
196196

197197
private IEncryptor _encryptor;
@@ -665,10 +665,10 @@ private void StartConnect()
665665
{
666666
switch (_config.proxyType)
667667
{
668-
case ProxyConfig.PROXY_SOCKS5:
668+
case ForwardProxyConfig.PROXY_SOCKS5:
669669
remote = new Socks5Proxy();
670670
break;
671-
case ProxyConfig.PROXY_HTTP:
671+
case ForwardProxyConfig.PROXY_HTTP:
672672
remote = new HttpProxy();
673673
break;
674674
default:

0 commit comments

Comments
 (0)