Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Added support for Brave (#22)
Browse files Browse the repository at this point in the history
* Added support for Brave
  • Loading branch information
osolmaz authored May 5, 2020
1 parent 088fa8b commit ad095e0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn init() -> Result<Option<Vec<Argument>>, 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";

Expand All @@ -44,6 +45,11 @@ pub fn init() -> Result<Option<Vec<Argument>>, 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")
Expand All @@ -65,6 +71,7 @@ pub fn init() -> Result<Option<Vec<Argument>>, 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);

Expand All @@ -79,6 +86,9 @@ pub fn init() -> Result<Option<Vec<Argument>>, 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hosts/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub fn install_host(browser: &Browser) -> Result<PathBuf, &'static str> {

// 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(
Expand Down
7 changes: 7 additions & 0 deletions src/hosts/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;
pub enum Browser {
Chrome,
Chromium,
Brave,
Firefox,
}

Expand Down Expand Up @@ -33,13 +34,19 @@ pub fn get_host_path(browser: &Browser) -> Result<PathBuf, &'static str> {
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/")
}
(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/")
}
Expand Down
2 changes: 1 addition & 1 deletion src/hosts/targets/chrome.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit ad095e0

Please sign in to comment.