Mstrodl / elcord

Discord Rich Presence / Gamebridge support for Emacs!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable elcord's rich presence when editing *scratch*

ralsei opened this issue · comments

I use emacs --daemon, and frequently get queries about why "I've been playing Emacs for two days".
When I'm not actively editing a file, Discord shows me as editing the scratchpad.
Hence, I'd like to have functionality where Elcord disables rich presence when editing the buffer *scratch*, possibly only if the daemon is enabled, which can be checked via (daemonp).

Funny you bring this up. I was considering something like this the other day when somebody asked me.

Here's one thing I considered: Have elcord disable itself when all visible* frames are closed, and have it automatically start up again on new frame creation. This way we get to keep using the daemon while having non-daemon-like behaviour.

Let me know what you think.

* visible because iirc running daemon mode has an invisible frame that always exists).

That seems pretty reasonable, especially compared to my proposal of disabling *scratch* (since there are valid reasons to be editing that buffer).

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

I'm using doom emacs and I keep on getting editing doom which is quite annoying :(

the above code works but it still shows scratch . Is the a way to filter it in (when (let ((frames (delete f (visible-frame-list)))) ?

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

Friendly reminder to ask if you got time for this :)

Cool.

I didn't have much time to work on it today but I hacked this up pretty quick (emphasis on the word "hack")

(defun elcord--disable-elcord-if-no-frames (f)
    (declare (ignore f))
    (when (let ((frames (delete f (visible-frame-list))))
            (or (null frames)
                (and (null (cdr frames))
                     (eq (car frames) terminal-frame))))
      (elcord-mode -1)
      (add-hook 'after-make-frame-functions 'elcord--enable-on-frame-created)))

  (defun elcord--enable-on-frame-created (f)
    (declare (ignore f))
    (elcord-mode +1))

  (defun my/elcord-mode-hook ()
    (if elcord-mode
        (add-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)
      (remove-hook 'delete-frame-functions 'elcord--disable-elcord-if-no-frames)))

  (add-hook 'elcord-mode-hook 'my/elcord-mode-hook)

should work in practical use-cases, though it looks like there's no hook for detecting when a frame goes invisible (without deleting it)

If I get time I'll do more on it

Thanks a lot, I've been searching for a way to do this 🙏🏻