Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hammerspoon does not respond/hang when the frontmost application does not respond #3606

Open
NightMachinery opened this issue Feb 28, 2024 · 0 comments

Comments

@NightMachinery
Copy link

NightMachinery commented Feb 28, 2024

Hammerspoon does not respond/hang when the frontmost application does not respond. I notice this most frequently with emacs, as emacs has terrible concurrency and does not respond to new events whenever it is doing sth heavy. This makes hammerspoon also not respond, which is terrible.

I have the following elisp code which "simulates" a hanged emacs:

(defun night/busy-spin (&optional duration)
  "Busy spin for DURATION seconds."
  (interactive "nDuration (seconds): ")
  (let ((end-time (time-add (current-time) (seconds-to-time (or duration 30)))))
    (while (time-less-p (current-time) end-time)
      ;; Do nothing except consume CPU cycles.
      )))

(night/busy-spin 20)

Using this, the code that causes Hammerspoon to hang seems to be this:

function toggleFocus(appName)
    local launch_p = false

    local app = nil
    app = hs.application.get(appName)

    if app then
        if app:isFrontmost() then
            app:hide()
        else
            app:activate()
        end
    else
        if launch_p then
            hs.application.launchOrFocus(appName)
            app = hs.application.get(appName)
        end
    end
end

When toggleFocus("org.gnu.Emacs") is run and emacs is hanged, Hammerspoon will hang.

How do I solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant