Caffeinate watcher is working only for few minutes
AvivWn opened this issue · comments
AvivWn commented
Hi,
I have recently experienced that Caffeinate watcher is working only for a few minutes, and then it is gone.
I am using it as:
function lockWatch(eventType)
if (eventType == hs.caffeinate.watcher.screensDidSleep) then
print('off')
elseif (eventType == hs.caffeinate.watcher.screensDidWake) then
print('on')
end
end
local lockWatcher = hs.caffeinate.watcher.new(lockWatch)
lockWatcher:start()
When reloading config, this works for the first few minutes. The console shows the prints for those events. Afterwards, the prints are gone, not sure why.
Let me know if it works for you for long.
Thanks in advance :)
Chris Jones commented
Remove local
from the penultimate line there and it will work properly.
Your watcher is being garbage-collected because "local" things go out of scope once your init.lua has been executed at startup 🙂
AvivWn commented
oh right
thanks 💯