fix: graceful shutdown

This commit is contained in:
sxyazi 2024-03-12 18:24:45 +08:00
parent 78b98a98c3
commit f168dbb1e3
No known key found for this signature in database
4 changed files with 27 additions and 23 deletions

View file

@ -46,7 +46,7 @@ impl Ueberzug {
tx.send(Some((path.to_path_buf(), rect)))?;
Adaptor::shown_store(rect, (0, 0));
} else {
bail!("uninitialized ueberzug");
bail!("uninitialized ueberzugpp");
}
let path = path.to_owned();
@ -66,12 +66,13 @@ impl Ueberzug {
if let Some(tx) = &*DEMON {
Ok(tx.send(None)?)
} else {
bail!("uninitialized ueberzug");
bail!("uninitialized ueberzugpp");
}
}
fn create_demon(adaptor: Adaptor) -> Result<Child> {
let result = Command::new("ueberzug")
// TODO: demon
let result = Command::new("ueberzugpp")
.args(["layer", "-so", &adaptor.to_string()])
.kill_on_drop(true)
.stdin(Stdio::piped())
@ -79,7 +80,7 @@ impl Ueberzug {
.spawn();
if let Err(ref e) = result {
warn!("ueberzug spawning failed: {}", e);
warn!("ueberzugpp spawning failed: {e}");
}
Ok(result?)
}
@ -98,9 +99,9 @@ impl Ueberzug {
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 {
debug!("ueberzug rect before adjustment: {:?}", rect);
debug!("ueberzugpp rect before adjustment: {:?}", rect);
let rect = Self::adjust_rect(rect);
debug!("ueberzug rect after adjustment: {:?}", rect);
debug!("ueberzugpp rect after adjustment: {:?}", rect);
let s = format!(
r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#,
@ -111,10 +112,10 @@ impl Ueberzug {
path.to_string_lossy(),
"\n"
);
debug!("ueberzug command: {}", s);
debug!("ueberzugpp command: {}", s);
stdin.write_all(s.as_bytes()).await?;
} else {
debug!("ueberzug command: remove");
debug!("ueberzugpp command: remove");
stdin
.write_all(format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, "\n").as_bytes())
.await?;

View file

@ -74,8 +74,11 @@ impl Boot {
println!(" WAYLAND_DISPLAY: {:?}", env::var_os("WAYLAND_DISPLAY"));
println!(" DISPLAY: {:?}", env::var_os("DISPLAY"));
println!("\nUeberzug");
println!(" Version: {:?}", std::process::Command::new("ueberzug").arg("--version").output());
println!("\nUeberzug++");
println!(
" Version: {:?}",
std::process::Command::new("ueberzugpp").arg("--version").output()
);
println!("\nWSL");
println!(

View file

@ -106,18 +106,18 @@ keymap = [
{ on = [ "N" ], run = "find_arrow --previous", desc = "Go to previous found file" },
# Sorting
{ on = [ ",", "m" ], run = "sort modified --dir-first", desc = "Sort by modified time" },
{ on = [ ",", "M" ], run = "sort modified --reverse --dir-first", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], run = "sort created --dir-first", desc = "Sort by created time" },
{ on = [ ",", "C" ], run = "sort created --reverse --dir-first", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], run = "sort extension --dir-first", desc = "Sort by extension" },
{ on = [ ",", "E" ], run = "sort extension --reverse --dir-first", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], run = "sort alphabetical --dir-first", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], run = "sort alphabetical --reverse --dir-first", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], run = "sort natural --dir-first", desc = "Sort naturally" },
{ on = [ ",", "N" ], run = "sort natural --reverse --dir-first", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], run = "sort size --dir-first", desc = "Sort by size" },
{ on = [ ",", "S" ], run = "sort size --reverse --dir-first", desc = "Sort by size (reverse)" },
{ on = [ ",", "m" ], run = "sort modified", desc = "Sort by modified time" },
{ on = [ ",", "M" ], run = "sort modified --reverse", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], run = "sort created", desc = "Sort by created time" },
{ on = [ ",", "C" ], run = "sort created --reverse", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], run = "sort extension", desc = "Sort by extension" },
{ on = [ ",", "E" ], run = "sort extension --reverse", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], run = "sort alphabetical", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], run = "sort alphabetical --reverse", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], run = "sort natural", desc = "Sort naturally" },
{ on = [ ",", "N" ], run = "sort natural --reverse", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], run = "sort size", desc = "Sort by size" },
{ on = [ ",", "S" ], run = "sort size --reverse", desc = "Sort by size (reverse)" },
# Tabs
{ on = [ "t" ], run = "tab_create --current", desc = "Create a new tab using the current path" },

View file

@ -27,7 +27,7 @@ impl Which {
};
if opt.tx.try_send(opt.idx).is_err() {
error!("callback: send error");
error!("which callback: send error");
}
}
}