DamienCassou / desktop-environment

Helps you control your GNU/Linux computer from Emacs
GNU General Public License v3.0
62 stars 20 forks source link

desktop-environment-toggle-music blocks emacs #37

Closed vslavkin closed 1 month ago

vslavkin commented 2 months ago

Throwing that command blocks emacs. I think it's because it's waiting for an output but the command doesn't output anything. I solved it temporarly using the following override:

    (advice-add 'desktop-environment-toggle-music :override
              (lambda ()
        (interactive)
        (start-process "playerctl" nil "playerctl" "play-pause")))

It would be good to show the status right after. The code of playerctl.el might be worth a look, even this package could use that one for the playerctl part.

vslavkin commented 2 months ago

Update: it fails with all the playerctl (music) commands

DamienCassou commented 2 months ago

would you mind sending a PR? I'm not sure we should add a dependency to playerctl because desktop-environment can be used with any command.

vslavkin commented 2 months ago

Sure, I'll try to do it.

vslavkin commented 2 months ago

Well, I spend quite a bit of time with this. Getting the output of an async shell command or a process isn't exactly easy. This is what worked:

(defun desktop-environment--process-filter (command msg)
  "Start a process of COMMAND and message MSG."
  (let ((proc (start-process-shell-command "desktop-environment-music" nil command)))
    (set-process-filter proc (lambda (proc line) (message "%s" msg)))))

Not my favourite approach. We could continue going this way, or ignore the output of playerctl (like playerctl.el). I couldn't get it to work with a function as filter that is passed as argument instead of the msg. I'm still unsure about why doesn't emacs detect that the playerctl command has finished. I guess it could be a problem of playerctl, but its unlikely.

DamienCassou commented 2 months ago

I have actually tried and things work fine for me, without any change. I'm using playerctl 2.4.1.

Can you please try:

$ playerctl --version
$ which playerctl

thank you

vslavkin commented 1 month ago

In my arch laptop, I've:

$ playerctl --version
v2.4.1

$ which playerctl
/usr/bin/playerctl

I've a desktop with nixos, so I'll check the output as soon as I'm able to

vslavkin commented 1 month ago

And for nix I have the same version and

$ which playerctl
/home/vslavkin/.nix-profile/bin/playerctl

Because that's how nix works.

DamienCassou commented 1 month ago

I have no clue what is going on for you, I'm sorry. I'm also using nix.

DamienCassou commented 1 month ago

And for nix I have the same version

can you reproduce the problem on both computers?

vslavkin commented 1 month ago

Yeah, with the override it "works", but it doesn't give me the output of the command (for when there's no player, etc) and I would have to override all the other commands. In both systems it blocks emacs.

vslavkin commented 1 month ago

Well, tried with emacs -Q (as I shoul've) and it works. I just though that if it didn't even work with M-!, it would change a lot if I did it with -Q I guess. Sorry to bother.

vslavkin commented 1 month ago

Yeah, after researching a bit, the problem seems to be when using emms. I can play-pause other media, but when pausing the emms music that is executing in the current emacs, it blocks and doesn't work if I don't do it async. Can you reproduce this behaviour @DamienCassou ?

DamienCassou commented 1 month ago

I'm using mpdel and not emms to play my music.

vslavkin commented 1 month ago

Thanks for your help, I'll look into mpdel!