Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Mar 8, 2023
2 parents a247a8a + b130ade commit f7a2f65
Show file tree
Hide file tree
Showing 44 changed files with 553 additions and 233 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# v2.7.355
### Client
* Farture: Windows: Add "Open in Browser" item to system menu
* Update: windows: ""Open in browser" if WebView is not initialized properly

### Server
* Farture: Merge Server Configuration
* Fix: Setting TCP kernel buffer
* Fix: Error in parsing IPNetwork as Range
* Update: Move NetFilter event from log to track
* Update: Set Send Kernel TCP buffer sizes
* Update: Use 24h in filename in track archives

# v2.7.350
### Client
* Feature: Follow server-supported networks by IP range
Expand Down
4 changes: 2 additions & 2 deletions Pub/Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "2.7.350",
"BumpTime": "2023-02-13T21:10:19.5187587Z",
"Version": "2.7.355",
"BumpTime": "2023-02-19T08:50:24.5778626Z",
"Prerelease": false,
"DeprecatedVersion": "2.0.0"
}
2 changes: 1 addition & 1 deletion VpnHood.Client.App.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void InitWebUi()
WebView.SetWebContentsDebuggingEnabled(true);
#endif
if (_appUi == null) throw new Exception($"{_appUi} is not initialized!");
WebView.LoadUrl($"{_appUi.Url}?nocache={_appUi.SpaHash}");
WebView.LoadUrl($"{_appUi.Url1}?nocache={_appUi.SpaHash}");
}

private void WebViewClient_PageLoaded(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client.App.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="350" package="com.vpnhood.client.android" android:installLocation="auto" android:versionName="2.7.350">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="355" package="com.vpnhood.client.android" android:installLocation="auto" android:versionName="2.7.355">
<uses-sdk android:minSdkVersion="22" android:targetSdkVersion="33" />
<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client.App.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions VpnHood.Client.App.UI/AppUIResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions VpnHood.Client.App.UI/AppUIResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@
<data name="Open" xml:space="preserve">
<value>Open</value>
</data>
<data name="OpenInBrowser" xml:space="preserve">
<value>Open in Browser</value>
</data>
</root>
4 changes: 2 additions & 2 deletions VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Tiny internal webserver to server your single-page application (SPA). You need this only if you want to create a UI for your VpnHood client by single-page application (SPA).</Description>
<PackageId>VpnHood.Client.App.UI</PackageId>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.355</Version>
<AssemblyVersion>2.7.355</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
32 changes: 18 additions & 14 deletions VpnHood.Client.App.UI/VpnHoodAppUI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
Expand All @@ -21,25 +22,26 @@ public class VpnHoodAppUi : IDisposable
private string? _indexHtml;
private WebServer? _server;
private string? _spaHash;
private string? _url;
private Uri? _url1;

private VpnHoodAppUi(Stream spaZipStream, int defaultPort = 0)
private VpnHoodAppUi(Stream spaZipStream, int defaultPort, Uri? url2)
{
if (IsInit) throw new InvalidOperationException($"{nameof(VpnHoodApp)} is already initialized!");
_spaZipStream = spaZipStream;
DefaultPort = defaultPort;
_instance = this;
DefaultPort = defaultPort;
Url2 = url2;
}

public int DefaultPort { get; }
public string Url => _url ?? throw new InvalidOperationException($"{nameof(Url)} is not initialized");
public Uri Url1 => _url1 ?? throw new InvalidOperationException($"{nameof(Url1)} is not initialized");
public Uri? Url2 { get; }

public string SpaHash =>
_spaHash ?? throw new InvalidOperationException($"{nameof(SpaHash)} is not initialized");

public static VpnHoodAppUi Instance => _instance ??
throw new InvalidOperationException(
$"{nameof(VpnHoodAppUi)} has not been initialized yet!");
public static VpnHoodAppUi Instance => _instance
?? throw new InvalidOperationException($"{nameof(VpnHoodAppUi)} has not been initialized yet!");

public static bool IsInit => _instance != null;

Expand All @@ -50,17 +52,17 @@ public void Dispose()
_instance = null;
}

public static VpnHoodAppUi Init(Stream zipStream, int defaultPort = 9090)
public static VpnHoodAppUi Init(Stream zipStream, int defaultPort = 9090, Uri? url2 = null)
{
var ret = new VpnHoodAppUi(zipStream, defaultPort);
var ret = new VpnHoodAppUi(zipStream, defaultPort, url2);
ret.Start();
return ret;
}

private void Start()
{
_url = $"http://{Util.GetFreeTcpEndPoint(IPAddress.Loopback, DefaultPort)}";
_server = CreateWebServer(Url, GetSpaPath());
_url1 = new Uri($"http://{Util.GetFreeTcpEndPoint(IPAddress.Loopback, DefaultPort)}");
_server = CreateWebServer(Url1, Url2, GetSpaPath());
try
{
Logger.UnregisterLogger<ConsoleLogger>();
Expand Down Expand Up @@ -111,14 +113,16 @@ private string GetSpaPath()
return path;
}

private WebServer CreateWebServer(string url, string spaPath)
private WebServer CreateWebServer(Uri url1, Uri? url2, string spaPath)
{
// read index.html for fallback
_indexHtml = File.ReadAllText(Path.Combine(spaPath, "index.html"));
var urlPrefixes = new string[] { url1.AbsoluteUri };
if (url2 != null) urlPrefixes = urlPrefixes.Concat(new[] { url2.AbsoluteUri }).ToArray();

// create the server
var server = new WebServer(o => o
.WithUrlPrefix(url)
.WithUrlPrefixes(urlPrefixes)
.WithMode(HttpListenerMode.EmbedIO))
.WithCors(
"https://localhost:8080, http://localhost:8080, https://localhost:8081, http://localhost:8081, http://localhost:30080") // must be first
Expand All @@ -136,7 +140,7 @@ private async Task ResponseSerializerCallback(IHttpContext context, object? data
context.Response.ContentType = MimeType.Json;
await using var text = context.OpenResponseText(new UTF8Encoding(false));
await text.WriteAsync(JsonSerializer.Serialize(data,
new JsonSerializerOptions {PropertyNamingPolicy = JsonNamingPolicy.CamelCase}));
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }));
}

// manage SPA fallback
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.App.Win/VpnHood.Client.App.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<PackageId>VpnHood.Client.App.Win</PackageId>
<StartupObject></StartupObject>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.355</Version>
<AssemblyVersion>2.7.355</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
Expand Down
10 changes: 6 additions & 4 deletions VpnHood.Client.App.Win/WebViewWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class WebViewWindow
private readonly Color _backColor = Color.FromArgb(34, 67, 166);
private readonly Size _defWindowSize = new(400, 700);
private readonly WebView2 _webView = new();

public bool IsInitCompleted { get; private set; }
public event EventHandler? InitCompleted;
public Form Form { get; }

public WebViewWindow(Uri url, string dataFolderPath)
{
Expand All @@ -40,11 +44,8 @@ public WebViewWindow(Uri url, string dataFolderPath)
_defWindowSize = new Size(_defWindowSize.Width * (Form.DeviceDpi / 96),
_defWindowSize.Height * (Form.DeviceDpi / 96));
UpdatePosition();

}

public Form Form { get; }

public static bool IsInstalled =>
Environment.Is64BitOperatingSystem
? Registry.GetValue(
Expand Down Expand Up @@ -94,7 +95,6 @@ public void Show()
return;
}


UpdatePosition();
Form.Show();
Form.BringToFront();
Expand All @@ -108,6 +108,8 @@ private void WebView_CoreWebView2InitializationCompleted(object? sender, EventAr
{
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = true;
webView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
IsInitCompleted = true;
InitCompleted?.Invoke(this, EventArgs.Empty);
}
}

Expand Down
Loading

0 comments on commit f7a2f65

Please sign in to comment.