Skip to content

Commit e3468c1

Browse files
committed
👷 pages: refactor exe path check
use `which` crate instead of unix `which` executable
1 parent 38ea470 commit e3468c1

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

‎Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ chwd = { git = "https://github.com/CachyOS/chwd", rev = "3b288ba0d86b1d078057eb7
2828
tracing = "0.1"
2929
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3030
tracing-appender = "0.2"
31+
which = { version = "7.0", features = ["tracing"] }
3132

3233
[build-dependencies]
3334
anyhow = "1"

‎src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn setup_logger() -> WorkerGuard {
1010

1111
// create subscriber env filter
1212
let subscriber_env_filter =
13-
env_filter.unwrap_or_else(|_| EnvFilter::new("debug,i18n_embed=warn"));
13+
env_filter.unwrap_or_else(|_| EnvFilter::new("debug,i18n_embed=warn,which=warn"));
1414

1515
// create stdout layer
1616
let stdout_log = tracing_subscriber::fmt::layer().compact().with_writer(std::io::stdout);

‎src/pages.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use once_cell::sync::Lazy;
1717
use phf::phf_ordered_map;
1818
use subprocess::{Exec, Redirection};
1919
use tracing::debug;
20+
use which::which;
2021

2122
#[macro_export]
2223
macro_rules! create_gtk_button {
@@ -1071,17 +1072,14 @@ fn on_appbtn_clicked(button: &gtk::Button) {
10711072
""
10721073
};
10731074

1074-
// Check if executable exists.
1075-
let exit_status = Exec::cmd("which").arg(binname).join().unwrap();
1076-
if !exit_status.success() {
1075+
// Get executable path, overwise return if it doesn't exist.
1076+
let exec_path = which(binname);
1077+
if exec_path.is_err() {
10771078
return;
10781079
}
10791080

10801081
// Get executable path.
1081-
let mut exe_path =
1082-
Exec::cmd("which").arg(binname).stdout(Redirection::Pipe).capture().unwrap().stdout_str();
1083-
exe_path.pop();
1084-
let bash_cmd = format!("{} &disown", &exe_path);
1082+
let bash_cmd = format!("{} &disown", exec_path.unwrap().to_str().unwrap());
10851083

10861084
// Create context channel.
10871085
let (tx, rx) = glib::MainContext::channel(glib::Priority::default());

0 commit comments

Comments
 (0)