Skip to content

Commit

Permalink
Extend AppOptions in win connect
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Dec 4, 2024
1 parent 609470e commit 7e8ec86
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Tests/VpnHood.Test/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static AppOptions CreateAppOptions()
var appOptions = new AppOptions("com.vpnhood.client.test") {
StorageFolderPath = Path.Combine(WorkingPath, "AppData_" + Guid.CreateVersion7()),
SessionTimeout = TimeSpan.FromSeconds(2),
AppGa4MeasurementId = null,
Ga4MeasurementId = null,
Tracker = tracker,
UseInternalLocationService = false,
UseExternalLocationService = false,
Expand Down
7 changes: 7 additions & 0 deletions VpnHood.Client.App.Win.Common.WpfSpa/AppOptionsEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VpnHood.Client.App.Win.Common.WpfSpa;

public class AppOptionsEx(string appId) : AppOptions(appId)
{
public bool ListenToAllIps { get; init; }
public int DefaultSpaPort { get; init; } = 80;
}
9 changes: 5 additions & 4 deletions VpnHood.Client.App.Win.Common.WpfSpa/VpnHoodWpfSpaApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VpnHood.Client.App.Win.Common.WpfSpa;
// ReSharper disable once RedundantExtendsListEntry
public abstract class VpnHoodWpfSpaApp : Application
{
protected abstract AppOptions CreateAppOptions();
protected abstract AppOptionsEx CreateAppOptions();

protected override void OnStartup(StartupEventArgs e)
{
Expand All @@ -31,13 +31,14 @@ protected override void OnStartup(StartupEventArgs e)
ArgumentNullException.ThrowIfNull(VpnHoodApp.Instance.Resource.SpaZipData);
using var spaResource = new MemoryStream(VpnHoodApp.Instance.Resource.SpaZipData);
var localSpaUrl = !string.IsNullOrEmpty(appOptions.LocalSpaHostName)
? VpnHoodWinApp.RegisterLocalDomain(new IPEndPoint(IPAddress.Parse("127.10.10.10"), 80), appOptions.LocalSpaHostName)
? VpnHoodWinApp.RegisterLocalDomain(new IPEndPoint(IPAddress.Parse("127.10.10.10"), appOptions.DefaultSpaPort), appOptions.LocalSpaHostName)
: null;
VpnHoodAppWebServer.Init(spaResource, url: localSpaUrl);
VpnHoodAppWebServer.Init(spaResource, defaultPort: appOptions.DefaultSpaPort, url: localSpaUrl,
listenToAllIps: appOptions.ListenToAllIps);

// initialize Win
VpnHoodWinApp.Instance.ExitRequested += (_, _) => Shutdown();
VpnHoodWinApp.Instance.OpenMainWindowInBrowserRequested += (_, _) =>
VpnHoodWinApp.Instance.OpenMainWindowInBrowserRequested += (_, _) =>
VpnHoodWinApp.OpenUrlInExternalBrowser(VpnHoodAppWebServer.Instance.Url);
VpnHoodWinApp.Instance.OpenMainWindowRequested += OpenMainWindowRequested;
VpnHoodWinApp.Instance.Start();
Expand Down
11 changes: 7 additions & 4 deletions VpnHood.Client.App.Win.Connect/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Main()
app.Run();
}

protected override AppOptions CreateAppOptions()
protected override AppOptionsEx CreateAppOptions()
{
// load app settings and resources
var storageFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VpnHoodConnect");
Expand All @@ -29,19 +29,22 @@ protected override AppOptions CreateAppOptions()
resources.Colors.ProgressBarColor = Color.FromArgb(231, 180, 129);

var appConfigs = AppConfigs.Load();
return new AppOptions("com.vpnhood.connect.windows") {
return new AppOptionsEx("com.vpnhood.connect.windows") {
UiName = "VpnHoodConnect",
StorageFolderPath = storageFolderPath,
DeviceId = WindowsIdentity.GetCurrent().User?.Value,
Resource = resources,
AccessKeys = [appConfigs.DefaultAccessKey],
UpdateInfoUrl = new Uri("https://github.com/vpnhood/VpnHood/releases/latest/download/VpnHoodConnect-win-x64.json"),
UpdateInfoUrl = new Uri("https://github.com/vpnhood/VpnHood-Connect/releases/latest/download/VpnHoodConnect-win-x64.json"),
UpdaterProvider = new WinAppUpdaterProvider(),
IsAddAccessKeySupported = false,
SingleLineConsoleLog = false,
LogAnonymous = !AppConfigs.IsDebugMode,
AllowEndPointTracker = appConfigs.AllowEndPointTracker,
LocalSpaHostName = "my-vpnhood-connect"
LocalSpaHostName = "my-vpnhood-connect",
Ga4MeasurementId = appConfigs.Ga4MeasurementId,
ListenToAllIps = appConfigs.ListenToAllIps,
DefaultSpaPort = appConfigs.DefaultSpaPort,
};
}
}
33 changes: 2 additions & 31 deletions VpnHood.Client.App.Win.Connect/AppConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,13 @@ internal class AppConfigs : Singleton<AppConfigs>
public string? UpdateInfoUrl { get; init; }
public bool ListenToAllIps { get; init; } = IsDebugMode;
public bool AllowEndPointTracker { get; init; }
public int? DefaultSpaPort { get; init; } = IsDebugMode ? 9571 : 9570;
public int DefaultSpaPort { get; init; } = IsDebugMode ? 9571 : 80;
public string? Ga4MeasurementId { get; init; }

// This is a test access key, you should replace it with your own access key.
// It is limited and can not be used in production.
public string DefaultAccessKey { get; init; } = ClientOptions.SampleAccessKey;

// Google sign-in (It is created through Firebase)
public string GoogleSignInClientId { get; init; } =
"000000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"; //YOUR_FIREBASE_CLIENT_ID

// VpnHood Store server
public string StoreBaseUri { get; init; } = new("https://store-api.vpnhood.com");

public Guid StoreAppId { get; init; } =
Guid.Parse("00000000-0000-0000-0000-000000000000"); //YOUR_VPNHOOD_STORE_APP_ID

public bool StoreIgnoreSslVerification { get; init; } = IsDebugMode;

// AdMob
// Default value is AdMob test AdUnit id, References: https://developers.google.com/admob/android/test-ads
// NOTE: AdMobApplicationId MUST BE SET
public const string AdMobApplicationId = "ca-app-pub-8662231806304184~1740102860"; //YOUR_ADMOB_APP_ID
public string AdMobInterstitialAdUnitId { get; init; } = "ca-app-pub-3940256099942544/8691691433";
public string AdMobInterstitialNoVideoAdUnitId { get; init; } = "ca-app-pub-3940256099942544/1033173712";

// Chartboost
public string ChartboostAppId { get; init; } = "000000000000000000000000"; //YOUR_CHATBOOST_APP_ID
public string ChartboostAppSignature { get; init; } = "0000000000000000000000000000000000000000"; //YOUR_CHATBOOST_APP_SIGNATURE
public string ChartboostAdLocation { get; init; } = "YOUR_CHARTBOOST_AD_LOCATION";

// Inmobi
public string InmobiAccountId { get; init; } = "000000000000000000000000"; //YOUR_INMMOBI_ACCOUNT_ID
public string InmobiPlacementId { get; init; } = "000000000000"; //YOUR_INMOBI_PLACEMENT_ID
public bool InmobiIsDebugMode { get; init; } = IsDebugMode;


public static AppConfigs Load()
{
var appConfigs = new AppConfigs();
Expand Down
7 changes: 4 additions & 3 deletions VpnHood.Client.App.Win/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public static void Main()
app.Run();
}

protected override AppOptions CreateAppOptions()
protected override AppOptionsEx CreateAppOptions()
{
return new AppOptions("com.vpnhood.client.windows") {
return new AppOptionsEx("com.vpnhood.client.windows") {
DeviceId = WindowsIdentity.GetCurrent().User?.Value,
StorageFolderPath = AppOptions.BuildStorageFolderPath(appId: "VpnHood"),
Resource = DefaultAppResource.Resource,
Expand All @@ -28,7 +28,8 @@ protected override AppOptions CreateAppOptions()
IsAddAccessKeySupported = true,
SingleLineConsoleLog = false,
LogAnonymous = !AssemblyInfo.IsDebugMode,
LocalSpaHostName = "my-vpnhood"
LocalSpaHostName = "my-vpnhood",
ListenToAllIps = AssemblyInfo.IsDebugMode
};
}
}
4 changes: 2 additions & 2 deletions VpnHood.Client.App/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AppOptions(string appId)
public static string BuildStorageFolderPath(string appId) =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), appId);

public string AppId { get; init; } = appId;
public string AppId { get; } = appId;
public string StorageFolderPath { get; set; } = BuildStorageFolderPath(appId);
public TimeSpan SessionTimeout { get; set; } = ClientOptions.Default.SessionTimeout;
public SocketFactory? SocketFactory { get; set; }
Expand All @@ -18,7 +18,7 @@ public static string BuildStorageFolderPath(string appId) =>
public bool UseInternalLocationService { get; set; } = true;
public bool UseExternalLocationService { get; set; } = true;
public AppResource Resource { get; set; } = new();
public string? AppGa4MeasurementId { get; set; } = "G-4LE99XKZYE";
public string? Ga4MeasurementId { get; set; } = "G-4LE99XKZYE";
public string? UiName { get; set; }
public bool IsAddAccessKeySupported { get; set; } = true;
public string[] AccessKeys { get; set; } = [];
Expand Down
1 change: 1 addition & 0 deletions VpnHood.Client.App/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class UserSettings
private static readonly ClientOptions DefaultClientOptions = new();

public AppLogSettings Logging { get; set; } = new();
public bool IsLicenseAccepted { get; set; }
public string? CultureCode { get; set; }
public Guid? ClientProfileId { get; set; }
public int MaxDatagramChannelCount { get; set; } = DefaultClientOptions.MaxDatagramChannelCount;
Expand Down
12 changes: 6 additions & 6 deletions VpnHood.Client.App/VpnHoodApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class VpnHoodApp : Singleton<VpnHoodApp>,
private readonly SocketFactory? _socketFactory;
private readonly bool _useInternalLocationService;
private readonly bool _useExternalLocationService;
private readonly string? _appGa4MeasurementId;
private readonly string? _ga4MeasurementId;
private bool _hasConnectRequested;
private bool _hasDisconnectRequested;
private bool _hasDiagnoseStarted;
Expand Down Expand Up @@ -107,7 +107,7 @@ private VpnHoodApp(IDevice device, AppOptions options)
_socketFactory = options.SocketFactory;
_useInternalLocationService = options.UseInternalLocationService;
_useExternalLocationService = options.UseExternalLocationService;
_appGa4MeasurementId = options.AppGa4MeasurementId;
_ga4MeasurementId = options.Ga4MeasurementId;
_versionCheckInterval = options.VersionCheckInterval;
_reconnectTimeout = options.ReconnectTimeout;
_autoWaitTimeout = options.AutoWaitTimeout;
Expand Down Expand Up @@ -172,7 +172,7 @@ private VpnHoodApp(IDevice device, AppOptions options)
IsQuickLaunchSupported = uiProvider.IsQuickLaunchSupported,
IsNotificationSupported = uiProvider.IsNotificationSupported,
IsAlwaysOnSupported = device.IsAlwaysOnSupported,
GaMeasurementId = options.AppGa4MeasurementId,
GaMeasurementId = options.Ga4MeasurementId,
ClientId = CreateClientId(options.AppId, options.DeviceId ?? Settings.ClientId)
};

Expand Down Expand Up @@ -248,11 +248,11 @@ private void ApplySettings()

private ITracker CreateBuildInTracker(string? userAgent)
{
if (string.IsNullOrEmpty(_appGa4MeasurementId))
if (string.IsNullOrEmpty(_ga4MeasurementId))
throw new InvalidOperationException("AppGa4MeasurementId is required to create a built-in tracker.");

var tracker = new Ga4TagTracker {
MeasurementId = _appGa4MeasurementId,
MeasurementId = _ga4MeasurementId,
SessionCount = 1,
ClientId = Settings.ClientId,
SessionId = Guid.NewGuid().ToString(),
Expand Down Expand Up @@ -427,7 +427,7 @@ public async Task Connect(

// initialize built-in tracker after acquire userAgent
if (Services.Tracker == null && UserSettings.AllowAnonymousTracker &&
!string.IsNullOrEmpty(_appGa4MeasurementId))
!string.IsNullOrEmpty(_ga4MeasurementId))
Services.Tracker = CreateBuildInTracker(userAgent);

// prepare logger
Expand Down

0 comments on commit 7e8ec86

Please sign in to comment.