Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-ne committed Jun 11, 2021
1 parent f2407eb commit 72b7b49
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin
obj
.vscode
.config
Releases
expresso
9 changes: 8 additions & 1 deletion ExpressVPNClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json.Linq;
using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace sttz.expresso
{
Expand All @@ -12,6 +13,8 @@ namespace sttz.expresso
/// </summary>
public class ExpressVPNClient : NativeMessagingClient
{


/// <summary>
/// ExpressVPN state.
/// </summary>
Expand Down Expand Up @@ -212,12 +215,16 @@ struct NoParams {}
/// </summary>
public event Action LocationsUpdated;

public static readonly string DefaultManifestName =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "com.expressvpn.helper.firefox"
: "com.expressvpn.helper";

/// <summary>
/// Create a new client and try to connect to the helper.
/// </summary>
/// <param name="logger">The instance to use for logging</param>
/// <returns></returns>
public ExpressVPNClient(ILogger logger) : base("com.expressvpn.helper", logger)
public ExpressVPNClient(ILogger logger) : base(DefaultManifestName, logger)
{
Task.Run(Process);
}
Expand Down
32 changes: 24 additions & 8 deletions NativeMessagingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
Expand All @@ -21,14 +22,29 @@ public class NativeMessagingClient
/// <summary>
/// Paths where the native messaging manifests are stored.
/// </summary>
static readonly string[] manifestBasePaths = new string[] {
"~/Library/Application Support/Mozilla/NativeMessagingHosts",
"/Library/Application Support/Mozilla/NativeMessagingHosts",
// These are used on Linux:
// "/usr/lib/mozilla/native-messaging-hosts",
// "/usr/lib64/mozilla/native-messaging-hosts",
// "~/.mozilla/native-messaging-hosts",
};
static readonly string[] manifestBasePaths =
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? new string[] {
"~/Library/Application Support/Mozilla/NativeMessagingHosts",
"/Library/Application Support/Mozilla/NativeMessagingHosts",
} :
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? new string[] {
"/usr/lib/mozilla/native-messaging-hosts",
"/usr/lib64/mozilla/native-messaging-hosts",
"~/.mozilla/native-messaging-hosts",
} :
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? new string[] {
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "/ExpressVPN/expressvpnd",
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "/ExpressVPN/expressvpnd",
} : new string[] { // If we can't detect the OS, try all the folders
"~/Library/Application Support/Mozilla/NativeMessagingHosts",
"/Library/Application Support/Mozilla/NativeMessagingHosts",
"/usr/lib/mozilla/native-messaging-hosts",
"/usr/lib64/mozilla/native-messaging-hosts",
"~/.mozilla/native-messaging-hosts",
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "/ExpressVPN/expressvpnd",
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "/ExpressVPN/expressvpnd",
};


/// <summary>
/// Extension of the native messaging manifest file.
Expand Down
6 changes: 3 additions & 3 deletions expresso.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand Down Expand Up @@ -31,8 +31,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 72b7b49

Please sign in to comment.