Skip to content

Commit f713865

Browse files
committed
fix: switch back to process checking
1 parent 2a90a5e commit f713865

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn handle_source(source: &str, target_dir: &PathBuf) -> Result<()> {
161161
}
162162

163163
pub fn switch(userchrome: &Userchrome, profile: String) -> Result<()> {
164-
utils::check_profile(&profile)?;
164+
utils::check_firefox()?;
165165

166166
print_userchrome(userchrome, false);
167167
println!();

src/utils.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
use std::{env, fs, io::Write, path::PathBuf, process::exit};
1+
use std::{
2+
env, fs,
3+
io::Write,
4+
path::PathBuf,
5+
process::{exit, Command},
6+
};
27

38
use anyhow::{anyhow, Result};
49
use colored::*;
@@ -63,22 +68,16 @@ pub fn download_zip(url: &str, target_dir: &PathBuf) -> Result<()> {
6368
Ok(())
6469
}
6570

66-
pub fn check_profile(profile: &str) -> Result<()> {
67-
let mut profile_contents = fs::read_dir(profile)?;
68-
let is_in_use = profile_contents.any(|f| {
69-
if let Ok(f) = f {
70-
let file_name = f.file_name().into_string();
71+
pub fn check_firefox() -> Result<()> {
72+
let mut processes_cmd = Command::new("ps");
73+
processes_cmd.args(vec!["xo", "comm="]);
74+
let processes_out = String::from_utf8(processes_cmd.output()?.stdout)?;
7175

72-
if let Ok(file_name) = file_name {
73-
return file_name.ends_with("shm") || file_name.ends_with("wal");
74-
}
75-
}
76-
77-
false
78-
});
79-
80-
if is_in_use {
81-
println!("{}", "Profile is in use, refusing to continue!".red());
76+
if processes_out
77+
.split('\n')
78+
.any(|f| f.to_lowercase().contains("firefox"))
79+
{
80+
println!("{}", "Firefox is running, refusing to continue!".yellow());
8281
exit(1);
8382
}
8483

0 commit comments

Comments
 (0)