Hammerspoon does not respond/hang when the frontmost application does not respond
NightMachinery opened this issue · comments
Feraidoon Mehri commented
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?