mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: register and ignore the SIGINT signal explicitly
This commit is contained in:
parent
fd8871d878
commit
4ff4038b41
2 changed files with 26 additions and 22 deletions
|
|
@ -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;
|
||||
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue