mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-23 01:40:51 +02:00
chore: linting
This commit is contained in:
@@ -372,108 +372,117 @@ impl BrowserRunner {
|
|||||||
profile.id
|
profile.id
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut actual_pid = launcher_pid;
|
|
||||||
|
|
||||||
// On macOS, when launching via `open -a`, the child PID is the `open` helper.
|
// On macOS, when launching via `open -a`, the child PID is the `open` helper.
|
||||||
// Resolve and store the actual browser PID for all browser types.
|
// Resolve and store the actual browser PID for all browser types.
|
||||||
#[cfg(target_os = "macos")]
|
let actual_pid = {
|
||||||
{
|
#[cfg(target_os = "macos")]
|
||||||
// Give the browser a moment to start
|
{
|
||||||
tokio::time::sleep(tokio::time::Duration::from_millis(1500)).await;
|
// Give the browser a moment to start
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_millis(1500)).await;
|
||||||
|
|
||||||
let system = System::new_all();
|
let system = System::new_all();
|
||||||
let profiles_dir = self.profile_manager.get_profiles_dir();
|
let profiles_dir = self.profile_manager.get_profiles_dir();
|
||||||
let profile_data_path = profile.get_profile_data_path(&profiles_dir);
|
let profile_data_path = profile.get_profile_data_path(&profiles_dir);
|
||||||
let profile_data_path_str = profile_data_path.to_string_lossy();
|
let profile_data_path_str = profile_data_path.to_string_lossy();
|
||||||
|
|
||||||
for (pid, process) in system.processes() {
|
let mut resolved_pid = launcher_pid;
|
||||||
let cmd = process.cmd();
|
|
||||||
if cmd.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if this process matches the intended browser type
|
for (pid, process) in system.processes() {
|
||||||
let exe_name_lower = process.name().to_string_lossy().to_lowercase();
|
let cmd = process.cmd();
|
||||||
let is_correct_browser = match profile.browser.as_str() {
|
if cmd.is_empty() {
|
||||||
"firefox" => {
|
continue;
|
||||||
exe_name_lower.contains("firefox")
|
|
||||||
&& !exe_name_lower.contains("developer")
|
|
||||||
&& !exe_name_lower.contains("camoufox")
|
|
||||||
}
|
}
|
||||||
"firefox-developer" => {
|
|
||||||
// More flexible detection for Firefox Developer Edition
|
// Determine if this process matches the intended browser type
|
||||||
(exe_name_lower.contains("firefox") && exe_name_lower.contains("developer"))
|
let exe_name_lower = process.name().to_string_lossy().to_lowercase();
|
||||||
|| (exe_name_lower.contains("firefox")
|
let is_correct_browser = match profile.browser.as_str() {
|
||||||
&& cmd.iter().any(|arg| {
|
"firefox" => {
|
||||||
let arg_str = arg.to_str().unwrap_or("");
|
exe_name_lower.contains("firefox")
|
||||||
arg_str.contains("Developer")
|
&& !exe_name_lower.contains("developer")
|
||||||
|| arg_str.contains("developer")
|
&& !exe_name_lower.contains("camoufox")
|
||||||
|| arg_str.contains("FirefoxDeveloperEdition")
|
}
|
||||||
|| arg_str.contains("firefox-developer")
|
"firefox-developer" => {
|
||||||
}))
|
// More flexible detection for Firefox Developer Edition
|
||||||
|| exe_name_lower == "firefox" // Firefox Developer might just show as "firefox"
|
(exe_name_lower.contains("firefox") && exe_name_lower.contains("developer"))
|
||||||
|
|| (exe_name_lower.contains("firefox")
|
||||||
|
&& cmd.iter().any(|arg| {
|
||||||
|
let arg_str = arg.to_str().unwrap_or("");
|
||||||
|
arg_str.contains("Developer")
|
||||||
|
|| arg_str.contains("developer")
|
||||||
|
|| arg_str.contains("FirefoxDeveloperEdition")
|
||||||
|
|| arg_str.contains("firefox-developer")
|
||||||
|
}))
|
||||||
|
|| exe_name_lower == "firefox" // Firefox Developer might just show as "firefox"
|
||||||
|
}
|
||||||
|
"zen" => exe_name_lower.contains("zen"),
|
||||||
|
"chromium" => exe_name_lower.contains("chromium") || exe_name_lower.contains("chrome"),
|
||||||
|
"brave" => exe_name_lower.contains("brave") || exe_name_lower.contains("Brave"),
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if !is_correct_browser {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
"zen" => exe_name_lower.contains("zen"),
|
|
||||||
"chromium" => exe_name_lower.contains("chromium") || exe_name_lower.contains("chrome"),
|
|
||||||
"brave" => exe_name_lower.contains("brave") || exe_name_lower.contains("Brave"),
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if !is_correct_browser {
|
// Check for profile path match
|
||||||
continue;
|
let profile_path_match = if matches!(
|
||||||
}
|
profile.browser.as_str(),
|
||||||
|
"firefox" | "firefox-developer" | "zen"
|
||||||
// Check for profile path match
|
) {
|
||||||
let profile_path_match = if matches!(
|
// Firefox-based browsers: look for -profile argument followed by path
|
||||||
profile.browser.as_str(),
|
let mut found_profile_arg = false;
|
||||||
"firefox" | "firefox-developer" | "zen"
|
for (i, arg) in cmd.iter().enumerate() {
|
||||||
) {
|
if let Some(arg_str) = arg.to_str() {
|
||||||
// Firefox-based browsers: look for -profile argument followed by path
|
if arg_str == "-profile" && i + 1 < cmd.len() {
|
||||||
let mut found_profile_arg = false;
|
if let Some(next_arg) = cmd.get(i + 1).and_then(|a| a.to_str()) {
|
||||||
for (i, arg) in cmd.iter().enumerate() {
|
if next_arg == profile_data_path_str {
|
||||||
if let Some(arg_str) = arg.to_str() {
|
found_profile_arg = true;
|
||||||
if arg_str == "-profile" && i + 1 < cmd.len() {
|
break;
|
||||||
if let Some(next_arg) = cmd.get(i + 1).and_then(|a| a.to_str()) {
|
}
|
||||||
if next_arg == profile_data_path_str {
|
|
||||||
found_profile_arg = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// Also check for combined -profile=path format
|
||||||
// Also check for combined -profile=path format
|
if arg_str == format!("-profile={profile_data_path_str}") {
|
||||||
if arg_str == format!("-profile={profile_data_path_str}") {
|
found_profile_arg = true;
|
||||||
found_profile_arg = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
// Check if the argument is the profile path directly
|
||||||
// Check if the argument is the profile path directly
|
if arg_str == profile_data_path_str {
|
||||||
if arg_str == profile_data_path_str {
|
found_profile_arg = true;
|
||||||
found_profile_arg = true;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
found_profile_arg
|
||||||
found_profile_arg
|
} else {
|
||||||
} else {
|
// Chromium-based browsers: look for --user-data-dir argument
|
||||||
// Chromium-based browsers: look for --user-data-dir argument
|
cmd.iter().any(|s| {
|
||||||
cmd.iter().any(|s| {
|
if let Some(arg) = s.to_str() {
|
||||||
if let Some(arg) = s.to_str() {
|
arg == format!("--user-data-dir={profile_data_path_str}")
|
||||||
arg == format!("--user-data-dir={profile_data_path_str}")
|
|| arg == profile_data_path_str
|
||||||
|| arg == profile_data_path_str
|
} else {
|
||||||
} else {
|
false
|
||||||
false
|
}
|
||||||
}
|
})
|
||||||
})
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if profile_path_match {
|
if profile_path_match {
|
||||||
let pid_u32 = pid.as_u32();
|
let pid_u32 = pid.as_u32();
|
||||||
if pid_u32 != launcher_pid {
|
if pid_u32 != launcher_pid {
|
||||||
actual_pid = pid_u32;
|
resolved_pid = pid_u32;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolved_pid
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
{
|
||||||
|
launcher_pid
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Update profile with process info and save
|
// Update profile with process info and save
|
||||||
let mut updated_profile = profile.clone();
|
let mut updated_profile = profile.clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user