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

View file

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

View file

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

View file

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