hrkfdn / ncspot

Cross-platform ncurses Spotify client written in Rust, inspired by ncmpc and the likes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exit with `ctrl+c` doesn't save state

ThomasFrans opened this issue · comments

Describe the bug

When ctrl+c is used to exit ncspot, the state isn't saved to disk. See #1393 for more information.

To Reproduce

Steps to reproduce the behavior:

  1. Open ncspot
  2. Play a song
  3. Exit using ctrl+c

Expected behavior

State should be persisted like when q or the 'quit' command are used.

System (please complete the following information):

  • OS: Arch Linux (and Windows #1393)
  • Terminal: Alacritty
  • Version: 1.0.0 (38010b4)
  • Installed from: cargo

I have looked around and this might be quite easy to implement by using the ctrlc crate. I can write some basic Rust and wouldn't might having a shot at implementing this feature if you can give some pointers at where this should go.

That would be a nice cross-platform solution. Another approach would be to add SIGINT to the currently handled signals, which would not work for Windows. I'm not entirely sure where to best put that code, but somewhere in the application or main modules could probably work.

I haven't used the ctrlc crate so I'm not sure how it notifies about the signal. If it's non-blocking, you could add it directly to the event loop. Otherwise use a worker thread/task and add a boolean/channel to the main event loop (Application::run()) so the program can be exited in a clean way.

I have tried for a few hours, but I can't get it to work. I could get a blocking call to work, but I couldn't get a multithreaded implementation to work. What I have discovered, though, is that Tokio also has an implementation, and it is probably possible to get it to work. I am simply not good enough at Rust to get it to work.

When I have time, I will look into this. That Tokio method looks convenient.