Skip to main content

brave_locations/
lib.rs

1//! Brave executable discovery helpers.
2
3use std::path::PathBuf;
4
5use browser_locations_core::{
6    Browser, discover_browser, locate_any_latest, locate_any_stable, locate_browser,
7};
8pub use browser_locations_core::{BrowserLocation, LocateError, ReleaseChannel, define_getter};
9
10/// Locates a Brave executable for a specific channel.
11///
12/// # Errors
13///
14/// Returns [`LocateError`] if the channel is unsupported or no executable is found.
15pub fn locate(channel: ReleaseChannel) -> Result<BrowserLocation, LocateError> {
16    locate_browser(Browser::Brave, channel)
17}
18
19/// Discovers installed Brave executables.
20#[must_use]
21pub fn discover() -> Vec<BrowserLocation> {
22    discover_browser(Browser::Brave)
23}
24
25define_getter!(
26    get_brave_path,
27    ReleaseChannel::Stable,
28    "Returns the stable Brave executable path."
29);
30define_getter!(
31    get_brave_beta_path,
32    ReleaseChannel::Beta,
33    "Returns the Brave beta executable path."
34);
35define_getter!(
36    get_brave_nightly_path,
37    ReleaseChannel::Nightly,
38    "Returns the Brave nightly executable path."
39);
40
41/// Returns the best available Brave executable, preferring stable first.
42///
43/// # Errors
44///
45/// Returns [`LocateError`] if no installed executable is found.
46pub fn get_any_brave_stable() -> Result<PathBuf, LocateError> {
47    locate_any_stable(Browser::Brave).map(|location| location.path)
48}
49
50/// Returns the best available Brave executable, preferring the newest channel first.
51///
52/// # Errors
53///
54/// Returns [`LocateError`] if no installed executable is found.
55pub fn get_any_brave_latest() -> Result<PathBuf, LocateError> {
56    locate_any_latest(Browser::Brave).map(|location| location.path)
57}