feat: fork instead of just spawning command

This commit is contained in:
Kat Inskip 2025-10-29 12:43:56 -07:00
parent ce503517bb
commit 17aab3c2d7
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
4 changed files with 39 additions and 25 deletions

10
Cargo.lock generated
View file

@ -164,6 +164,15 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]]
name = "fork"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed479091df6b84e9670acc5fa0339f1d2c6b7459e432455a26c75848048ae14d"
dependencies = [
"libc",
]
[[package]]
name = "freedesktop-desktop-entry"
version = "0.7.19"
@ -185,6 +194,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"fork",
"freedesktop-desktop-entry",
"indexmap",
"is_executable",

View file

@ -8,6 +8,7 @@ edition = "2024"
[dependencies]
anyhow = "1.0.100"
clap = { version = "4.5.50", features = ["derive"] }
fork = "0.3.1"
freedesktop-desktop-entry = "0.7.19"
indexmap = { version = "2.12.0", features = ["serde"] }
is_executable = "1.0.5"

View file

@ -8,9 +8,10 @@ rustPlatform.buildRustPackage (_finalAttrs: {
src = ./.;
cargoHash = "sha256-aaLgttzAlHJciCDn9vQ2bHPoNc6lcXQa4GIJQPvUgyw=";
cargoHash = "sha256-gwaH/Q9VN1i3JLruj6aRBhInWy+qHV+g32wSKY++msw=";
meta = {
mainProgram = "fzfdapter";
description = "fzfdapter, a fuzzel/wofi/rofi... thing for your terminal";
homepage = "https://github.com/kittywitch/fzfdapter";
license = lib.licenses.gpl3;

View file

@ -1,12 +1,10 @@
use {
crate::config::AdapterConfig,
anyhow::anyhow,
std::{
crate::config::AdapterConfig, anyhow::anyhow, fork::{daemon, Fork}, std::{
mem,
path::Path,
process::{Command, Stdio},
sync::Arc,
},
}
};
#[derive(Clone, Debug)]
@ -18,15 +16,17 @@ pub(crate) enum WhatDo {
pub(crate) fn handle_xdg(exec: Vec<String>) -> anyhow::Result<()> {
let args = exec.get(1..).unwrap_or_default();
let exec_run = Command::new(exec.first().ok_or(anyhow!(
"Command not provided within the XDG desktop file correctly?"
))?)
.args(args)
.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
mem::forget(exec_run);
if let Ok(Fork::Child) = daemon(false, false) {
let exec_run = Command::new(exec.first().ok_or(anyhow!(
"Command not provided within the XDG desktop file correctly?"
))?)
.args(args)
.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
mem::forget(exec_run);
}
Ok(())
}
@ -34,16 +34,18 @@ pub(crate) fn handle_terminal(config: &AdapterConfig, args: &[&str]) -> anyhow::
let mut in_args = args.iter().map(|x| x.to_string()).collect();
let mut term_args = config.terminal_args();
term_args.append(&mut in_args);
let term_run = Command::new(
config
.terminal_bin()
.ok_or(anyhow!("No defined or available terminal"))?,
)
.args(term_args)
.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
mem::forget(term_run);
if let Ok(Fork::Child) = daemon(false, false) {
let term_run = Command::new(
config
.terminal_bin()
.ok_or(anyhow!("No defined or available terminal"))?,
)
.args(term_args)
.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
mem::forget(term_run);
}
Ok(())
}