diff --git a/.gitignore b/.gitignore index a8b58c8..bbea963 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin obj .vscode +.config Releases expresso diff --git a/ExpressVPNClient.cs b/ExpressVPNClient.cs index 83e2218..c592c58 100644 --- a/ExpressVPNClient.cs +++ b/ExpressVPNClient.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Linq; using System; using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace sttz.expresso { @@ -12,6 +13,8 @@ namespace sttz.expresso /// public class ExpressVPNClient : NativeMessagingClient { + + /// /// ExpressVPN state. /// @@ -212,12 +215,16 @@ struct NoParams {} /// public event Action LocationsUpdated; + public static readonly string DefaultManifestName = + RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "com.expressvpn.helper.firefox" + : "com.expressvpn.helper"; + /// /// Create a new client and try to connect to the helper. /// /// The instance to use for logging /// - public ExpressVPNClient(ILogger logger) : base("com.expressvpn.helper", logger) + public ExpressVPNClient(ILogger logger) : base(DefaultManifestName, logger) { Task.Run(Process); } diff --git a/NativeMessagingClient.cs b/NativeMessagingClient.cs index 7c74ece..b6f2a0a 100644 --- a/NativeMessagingClient.cs +++ b/NativeMessagingClient.cs @@ -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; @@ -21,14 +22,29 @@ public class NativeMessagingClient /// /// Paths where the native messaging manifests are stored. /// - 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", + }; + /// /// Extension of the native messaging manifest file. diff --git a/expresso.csproj b/expresso.csproj index a917d34..09f45bd 100644 --- a/expresso.csproj +++ b/expresso.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net472 + net5.0 @@ -31,8 +31,8 @@ - - + +