Skip to content

Commit

Permalink
fix: register and ignore the SIGINT signal explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Nov 12, 2024
1 parent fd8871d commit 4ff4038
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
31 changes: 15 additions & 16 deletions yazi-adapter/src/ueberzug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use yazi_shared::{RoCell, env_exists};

use crate::{Adapter, Dimension};

#[allow(clippy::type_complexity)]
static DEMON: RoCell<Option<UnboundedSender<Option<(PathBuf, Rect)>>>> = RoCell::new();
type Cmd = Option<(PathBuf, Rect)>;

static DEMON: RoCell<Option<UnboundedSender<Cmd>>> = RoCell::new();

pub(super) struct Ueberzug;

Expand All @@ -34,7 +35,7 @@ impl Ueberzug {
child = Self::create_demon(adapter).ok();
}
if let Some(c) = &mut child {
Self::send_command(c, cmd).await.ok();
Self::send_command(adapter, c, cmd).await.ok();
}
}
});
Expand Down Expand Up @@ -108,30 +109,28 @@ impl Ueberzug {
rect
}

async fn send_command(child: &mut Child, cmd: Option<(PathBuf, Rect)>) -> Result<()> {
let stdin = child.stdin.as_mut().unwrap();
if let Some((path, rect)) = cmd {
async fn send_command(adapter: Adapter, child: &mut Child, cmd: Cmd) -> Result<()> {
let s = if let Some((path, rect)) = cmd {
debug!("ueberzugpp rect before adjustment: {:?}", rect);
let rect = Self::adjust_rect(rect);
debug!("ueberzugpp rect after adjustment: {:?}", rect);

let s = format!(
format!(
r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#,
rect.x,
rect.y,
rect.width,
rect.height,
path.to_string_lossy(),
"\n"
);
debug!("ueberzugpp command: {}", s);
stdin.write_all(s.as_bytes()).await?;
'\n'
)
} else {
debug!("ueberzugpp command: remove");
stdin
.write_all(format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, "\n").as_bytes())
.await?;
}
format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, '\n')
};

debug!("`ueberzugpp layer -so {adapter}` command: {s}");
child.stdin.as_mut().unwrap().write_all(s.as_bytes()).await?;

Ok(())
}
}
17 changes: 11 additions & 6 deletions yazi-fm/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ impl Signals {
#[cfg(unix)]
#[inline]
fn handle_sys(n: libc::c_int) -> bool {
use libc::{SIGCONT, SIGHUP, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP};
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP};
use tracing::error;
use yazi_proxy::{AppProxy, HIDER};

match n {
SIGHUP | SIGTERM | SIGQUIT => {
SIGINT => { /* ignored */ }
SIGQUIT | SIGHUP | SIGTERM => {
Event::Quit(Default::default()).emit();
return false;
}
Expand Down Expand Up @@ -73,13 +74,17 @@ impl Signals {

fn spawn(mut rx: mpsc::UnboundedReceiver<(bool, Option<oneshot::Sender<()>>)>) -> Result<()> {
#[cfg(unix)]
use libc::{SIGCONT, SIGHUP, SIGQUIT, SIGTERM, SIGTSTP};
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGTSTP};

#[cfg(unix)]
let mut sys = signal_hook_tokio::Signals::new([
// Terminating signals
SIGHUP, SIGTERM, SIGQUIT, //
// Job control signals
// Interrupt signals (Ctrl-C, Ctrl-\)
SIGINT, SIGQUIT, //
// Hangup signal (Terminal closed)
SIGHUP, //
// Termination signal (kill)
SIGTERM, //
// Job control signals (Ctrl-Z, fg/bg)
SIGTSTP, SIGCONT,
])?;
#[cfg(windows)]
Expand Down

0 comments on commit 4ff4038

Please sign in to comment.