Skip to content

Commit

Permalink
👷 pages: refactor exe path check
Browse files Browse the repository at this point in the history
use `which` crate instead of unix `which` executable
  • Loading branch information
vnepogodin committed Jan 4, 2025
1 parent 38ea470 commit e3468c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ chwd = { git = "https://github.com/CachyOS/chwd", rev = "3b288ba0d86b1d078057eb7
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2"
which = { version = "7.0", features = ["tracing"] }

[build-dependencies]
anyhow = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn setup_logger() -> WorkerGuard {

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

// create stdout layer
let stdout_log = tracing_subscriber::fmt::layer().compact().with_writer(std::io::stdout);
Expand Down
12 changes: 5 additions & 7 deletions src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use once_cell::sync::Lazy;
use phf::phf_ordered_map;
use subprocess::{Exec, Redirection};
use tracing::debug;
use which::which;

#[macro_export]
macro_rules! create_gtk_button {
Expand Down Expand Up @@ -1071,17 +1072,14 @@ fn on_appbtn_clicked(button: &gtk::Button) {
""
};

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

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

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

0 comments on commit e3468c1

Please sign in to comment.