Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
crowser = "0.4.1"
dirs = "6.0.0"
uuid = { version = "1", features = ["v4", "serde"] }


141 changes: 141 additions & 0 deletions apps/desktop/src-tauri/src/browser_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use crowser::{browser};
use std::{fs, path::PathBuf, io::{self, Read}};
use dirs::{config_dir, data_local_dir};
use serde_json::Value;

pub enum Browsers {
Chrome,
Edge,
Brave,
FireFox,
Safari
}

pub fn get_browsers() -> Vec<String> {
let browser_vector = browser::get_all_existing_browsers();
let browser_names: Vec<String> = browser_vector.iter().map(|s| s.name.to_owned()).collect();

return browser_names;
}

pub fn get_chrome_based_profiles(os_paths: Vec<&str>) -> Result<Vec<String>, Box<dyn std::error::Error>> {

let base_dir = if cfg!(target_os = "windows") || cfg!(target_os = "macos") {
data_local_dir()
} else {
config_dir()
};

if let Some(mut path) = base_dir {

#[cfg(target_os = "windows")]
path.push(os_paths[0]);

#[cfg(target_os = "macos")]
path.push(os_paths[1]);

#[cfg(target_os = "linux")]
path.push(os_paths[2]);

if path.exists() {

let mut file = fs::File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

let json_value: Value = serde_json::from_str(&contents)?;

let info_cache = json_value
.get("profile")
.and_then(|p| p.get("info_cache"))
.and_then(|ic| ic.as_object())
.ok_or_else(|| {Box::new(io::Error::new(io::ErrorKind::InvalidData, "Could not find 'profile' or 'info_cache' in JSON.")) as Box<dyn std::error::Error>})?;

let mut profile_names: Vec<String> = Vec::new();

for (_profile_key, profile_data) in info_cache.iter() {
if let Some(name_value) = profile_data.get("gaia_name") {
if let Some(name_str) = name_value.as_str() {
profile_names.push(name_str.to_owned());
}
}
}

return Ok(profile_names);

}
}

Ok(Vec::new())
}

pub fn get_chrome_profiles(kind: Browsers) -> Result<Vec<String>, Box<dyn std::error::Error>> {

let paths: Vec<&str> = match kind {
Browsers::Chrome => vec![
"Google\\Chrome\\User Data\\Local State",
"Google/Chrome/Local State",
"google-chrome/Local State",
],
Browsers::Edge => vec![
"Microsoft\\Edge\\User Data\\Local State",
"Microsoft/Edge/Local State",
"microsoft-edge/Local State",
],
Browsers::Brave => vec![
"BraveSoftware\\Brave-Browser\\User Data\\Local State",
"BraveSoftware/Brave-Browser/Local State",
"brave/Local State",
],
_ => return Ok(Vec::new()),
};

return get_chrome_based_profiles(paths);
}

pub fn get_firefox_profiles() -> Result<Vec<String>, Box<dyn std::error::Error>> {

let base_dir = if cfg!(target_os = "windows") || cfg!(target_os = "macos") {
data_local_dir()
} else {
dirs::home_dir()
Comment on lines +98 to +101

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Firefox profiles looked up under Local instead of Roaming AppData

On Windows the function builds the base directory using dirs::data_local_dir() before appending Mozilla\Firefox\Profiles, but Firefox stores profiles under %APPDATA% (Roaming) rather than Local. With the current path the directory almost always does not exist, so the function returns an empty list even when profiles are present. Use dirs::data_dir() or the roaming path instead.

Useful? React with 👍 / 👎.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdityaVKochar can you verify this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for both local and roaming
tested

};

if let Some(mut path) = base_dir {

#[cfg(target_os = "windows")]
path.push("Mozilla\\Firefox\\Profiles");

#[cfg(target_os = "macos")]
path.push("Firefox/Profiles");

#[cfg(target_os = "linux")]
path.push("~/.mozilla/firefox");

if path.exists() {
match fs::read_dir(path) {
Ok(entries) => {
let profile_names: Vec<String> = entries
.filter_map(Result::ok)
.filter_map(|entry| {
match entry.file_type() {
Ok(file_type) if file_type.is_dir() => {
Some(entry.file_name().to_string_lossy().into_owned())
}
_ => None,
}
})
.collect();
return Ok(profile_names);
}
Err(e) => {
eprintln!("Error reading directory: {}", e);
return Ok(Vec::new());
}
}
}
}

return Ok(Vec::new());

}
4 changes: 4 additions & 0 deletions apps/desktop/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[tauri::command]
pub fn get_available_browser() {
get_browsers();
}