sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.

Home Page:https://yazi-rs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`ya.manager_emit("quit", {})` shows "task running" confirmation popup

kohane27 opened this issue · comments

What system are you running Yazi on?

Linux Wayland

What terminal are you running Yazi in?

kitty 0.33.1

Did you try the latest code to see if this problem got fixed?

Tried, but the problem still

yazi --debug output

Yazi
    Version: 0.2.5 (0ff4835 2024-05-18)
    OS: linux-x86_64 (unix)
    Debug: false

Ya
    Version: Ok(Output { status: ExitStatus(unix_wait_status(0)), stdout: "Ya 0.2.5 (0ff4835 2024-05-18)\n", stderr: "" })

Emulator
    Emulator.via_env: ("xterm-kitty", "tmux")
    Emulator.via_csi: Ok(Kitty)
    Emulator.detect: Kitty

Adaptor
    Adaptor.matches: Kitty

Desktop
    XDG_SESSION_TYPE: Some("wayland")
    WAYLAND_DISPLAY: Some("wayland-1")
    DISPLAY: Some(":0")

SSH
    shared.in_ssh_connection: false

WSL
    /proc/sys/fs/binfmt_misc/WSLInterop: false

Variables
    SHELL: Some("/usr/bin/zsh")
    EDITOR: Some("nvim")
    ZELLIJ_SESSION_NAME: None
    YAZI_FILE_ONE: None
    YAZI_CONFIG_HOME: None

file(1)
    Version: Ok(Output { status: ExitStatus(unix_wait_status(0)), stdout: "file-5.45\nmagic file from /usr/share/file/misc/magic\nseccomp support included\n", stderr: "" })

Text Opener
    default: Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block: Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

tmux
    TMUX: true

Ueberzug++
    Version: Ok(Output { status: ExitStatus(unix_wait_status(0)), stdout: "ueberzugpp 2.9.5\n", stderr: "" })

Describe the bug

Hello! Hope you're doing well. Thank you for creating this awesome modern terminal file manager. I've been enjoying it a lot!

Description

I'm trying to create a plugin that exit yazi after opening nvim. The goal is dropped to the shell after quitting nvim. Use case:

  1. Open a file in yazi
  2. Inside nvim to do some editing
  3. Quit nvim
  4. Drop into the shell (as opposite to be back in yazi)

plugins/exit-open.yazi/init.lua:

local hover_url = ya.sync(function()
  return tostring(cx.active.current.hovered.url)
end)

return {
  entry = function(_, args)
      local absolute_path = tostring(hover_url())
      local command = "nvim " .. ya.quote(absolute_path)
      ya.manager_emit("shell", { block = true, confirm = true, command })
      ya.manager_emit("quit", {})
  end,
}

keymap.toml:

{ on = [ "e" ], run = "plugin exit-open", desc = "Open nvim" },

The following happens:

yazi-.mp4

The following confirmation popup shows up in a split of a second:

2024-05-19-19-51-27

I realized the same happens with just the following:

return {
  entry = function(_, args)
      ya.manager_emit("quit", {})
  end,
}

However, the following has no such confirmation popup:

{ on = [ "q" ], run = "quit", desc = "Exit the process" },

Any input is much appreciated. Thank you!

Expected Behavior

yazi process is quit without the task running confirmation popup

To Reproduce

Please see above

Anything else?

Thank you!

Hi, this is expected because when manager_emit("quit") is sent to quit Yazi, there are still tasks (the plugin itself) running, so this prompt pops up for safety reasons. Forcing a quit might lead to data loss because Yazi doesn't know if the plugin is doing something critical, like copying files.

But the prompt only pops up briefly and disappears once the manager_emit("quit") call finishes, and Yazi will also close - I added a detection mechanism to this prompt a few days ago: when it appears, it keeps checking for 3 seconds, and if all tasks are done within those 3 seconds, it automatically confirms the prompt and exits Yazi:

_ = time::sleep(Duration::from_millis(100)) => {
i += 1;
if i > 30 { break }
else if ongoing.lock().len() == 0 {
emit!(Quit(opt));
return;
}
}

I think this should work for most cases, even though it might flash quickly on the screen, in your case, it should be short enough that the user won't really notice it.

Thank you for getting back to me with a detailed explanation; really appreciate it:)!

I'm going to lock this issue because it has been closed for 30 days. ⏳
This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.