vpnhood / VpnHood

Undetectable Fast Portable VPN
GNU Lesser General Public License v2.1
992 stars 149 forks source link

Error in Maui android #473

Closed SalimiHabib closed 8 months ago

SalimiHabib commented 8 months ago

hi

we try to use VpnHoodClient in maui

.csproj

 <PackageReference Include="VpnHood.Client.App" Version="3.3.470" />
 <PackageReference Include="VpnHood.Client.Device" Version="3.3.470" />
 <PackageReference Include="VpnHood.Client.Device.WinDivert" Version="3.3.470" />

Mainactivity

protected override void OnCreate(Bundle? savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    if (!VpnHoodApp.IsInit)
        VpnHoodApp.Init(new AndroidDevice(), new AppOptions());

android manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:allowBackup="true" android:icon="@mipmap/appicon"
                 android:roundIcon="@mipmap/appicon_round" 
                 android:supportsRtl="true">

  </application>

  <uses-feature android:name="android.software.leanback" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />

  <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
  <uses-permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND" />
  <uses-permission android:name="android.permission.BIND_REMOTEVIEWS" />
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="http" />
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="https" />
    </intent>
  </queries>

</manifest>

connect method in Mainactivity


private async Task ConnectTask(Guid? clientId, string? accessKey, VpnHood.Common.Token? accessKeyToken, GoToState command)
{
    try
    {
        Guard.Against.Null(clientId, nameof(clientId));
        Guard.Against.Null(accessKey, nameof(accessKey));
        Guard.Against.Null(accessKeyToken, nameof(accessKeyToken));

        ClientProfile profile = _appState.HoodApp.ClientProfileService.ImportAccessKey(accessKey);

        VpnHoodApp.Instance.ConnectionStateChanged += (_, _) => UpdateUi();

        _connectCts = new CancellationTokenSource();

        await  VpnHoodApp.Instance.Connect(clientId, cancellationToken: _connectCts.Token);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

and error


   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.Single[ClientProfile](IEnumerable`1 source, Func`2 predicate)
   at VpnHood.Client.App.ClientProfileService.Get(Guid clientProfileId)
   at VpnHood.Client.App.VpnHoodApp.Connect(Nullable`1 clientProfileId, Boolean diagnose, String userAgent, Boolean throwException, CancellationToken cancellationToken)
   at VpnHood.Client.App.VpnHoodApp.Connect(Nullable`1 clientProfileId, Boolean diagnose, String userAgent, Boolean throwException, CancellationToken cancellationToken)
   at aco.gc.MainActivity.ConnectTask(Nullable`1 clientId, String accessKey, Token accessKeyToken, GoToState command) in C:\Users\sina\source\repos\aco.vpn\aco.gc\Platforms\Android\MainActivity.cs:line 95

Thank you

trudyhood commented 8 months ago

Connect needs clientProfileId not clientId. Anyway, our code support is limited. Please compare the code with the official repo.