From ad095e0a1299a0e62987ec89feadab7121f15bb9 Mon Sep 17 00:00:00 2001 From: Onur Solmaz Date: Tue, 5 May 2020 18:41:37 +0200 Subject: [PATCH] Added support for Brave (#22) * Added support for Brave --- src/cli.rs | 10 ++++++++++ src/hosts/installer.rs | 4 ++-- src/hosts/paths.rs | 7 +++++++ src/hosts/targets/chrome.rs | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 9488849..c68e35b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,6 +22,7 @@ pub fn init() -> Result>, CliError> { let chrome_arg = "chrome"; let chromium_arg = "chromium"; let firefox_arg = "firefox"; + let brave_arg = "brave"; let list_arg = "list"; let open_arg = "open"; @@ -44,6 +45,11 @@ pub fn init() -> Result>, CliError> { .long("--install-firefox") .help("Install the native messaging host for Firefox."), ) + .arg( + Arg::with_name(brave_arg) + .long("--install-brave") + .help("Install the native messaging host for Brave."), + ) .arg( Arg::with_name(list_arg) .short("-l") @@ -65,6 +71,7 @@ pub fn init() -> Result>, CliError> { let install_chrome = matches.is_present(chrome_arg); let install_chromium = matches.is_present(chromium_arg); let install_firefox = matches.is_present(firefox_arg); + let install_brave = matches.is_present(brave_arg); let list_bookmarks = matches.is_present(list_arg); let open_bookmark_ids = matches.values_of(open_arg); @@ -79,6 +86,9 @@ pub fn init() -> Result>, CliError> { if install_firefox { args.push(Argument::InstallBrowserHost(Browser::Firefox)); } + if install_brave { + args.push(Argument::InstallBrowserHost(Browser::Brave)); + } if list_bookmarks { args.push(Argument::ListBookmarks); } diff --git a/src/hosts/installer.rs b/src/hosts/installer.rs index 5ee58b5..ed9913a 100644 --- a/src/hosts/installer.rs +++ b/src/hosts/installer.rs @@ -25,9 +25,9 @@ pub fn install_host(browser: &Browser) -> Result { // Write to created file match browser { - Browser::Chrome | Browser::Chromium => file.write_all( + Browser::Chrome | Browser::Chromium | Browser::Brave => file.write_all( &serde_json::to_string(&ChromeHost::new(exe_path)) - .map_err(|_| "Failed to serialise Chrome/Chromium browser host.")? + .map_err(|_| "Failed to serialise Chrome/Chromium/Brave browser host.")? .as_bytes(), ), Browser::Firefox => file.write_all( diff --git a/src/hosts/paths.rs b/src/hosts/paths.rs index 96fc524..4b3b827 100644 --- a/src/hosts/paths.rs +++ b/src/hosts/paths.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; pub enum Browser { Chrome, Chromium, + Brave, Firefox, } @@ -33,6 +34,9 @@ pub fn get_host_path(browser: &Browser) -> Result { let nm_dir_from_home = match (os_type, browser) { (OsType::Linux, Browser::Chrome) => Ok(".config/google-chrome/NativeMessagingHosts/"), (OsType::Linux, Browser::Chromium) => Ok(".config/chromium/NativeMessagingHosts/"), + (OsType::Linux, Browser::Brave) => { + Ok(".config/BraveSoftware/Brave-Browser/NativeMessagingHosts/") + } (OsType::Linux, Browser::Firefox) => Ok(".mozilla/native-messaging-hosts/"), (OsType::MacOS, Browser::Chrome) => { Ok("Library/Application Support/Google/Chrome/NativeMessagingHosts/") @@ -40,6 +44,9 @@ pub fn get_host_path(browser: &Browser) -> Result { (OsType::MacOS, Browser::Chromium) => { Ok("Library/Application Support/Chromium/NativeMessagingHosts/") } + (OsType::MacOS, Browser::Brave) => { + Ok("Library/Application Support/BraveSoftware/Brave-Browser/NativeMessagingHosts/") + } (OsType::MacOS, Browser::Firefox) => { Ok("Library/Application Support/Mozilla/NativeMessagingHosts/") } diff --git a/src/hosts/targets/chrome.rs b/src/hosts/targets/chrome.rs index 0dc65d8..8ba9970 100644 --- a/src/hosts/targets/chrome.rs +++ b/src/hosts/targets/chrome.rs @@ -1,4 +1,4 @@ -// This host is usable for both Chrome and Chromium +// This host is usable for both Chrome, Chromium and Brave #[derive(Serialize)] pub struct ChromeHost { name: &'static str,