-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaffeinate.lua
47 lines (38 loc) · 1.31 KB
/
caffeinate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--
-- Caffeinate for better sleep
--
local logger = hs.logger.new('cafe', 'info')
Cafe = {}
Cafe.isSleeping = false
Cafe.isLocked = false
Cafe.wakeUpTime = os.time()
-- https://www.hammerspoon.org/docs/hs.caffeinate.watcher.html#systemDidWake
function Cafe.cafeHandler(eventType)
logger:d('Cafe', eventType)
if (eventType == hs.caffeinate.watcher.systemDidWake) then
logger:i('')
logger:i('===================')
logger:i('=== Hallo Hallo ===')
logger:i('===================')
Cafe.isSleeping = false
Cafe.wakeUpTime = os.time()
-- Sometimes Redshift doesn't work well after restarting
-- e.g., Redshift: still on when it shouldn't / one monitor doesn't have a warm color
-- (a similar issue https://github.com/Hammerspoon/hammerspoon/issues/1197)
--
-- reload() distrubs timer.
--hs.reload()
elseif (eventType == hs.caffeinate.watcher.systemWillSleep) then
Cafe.isSleeping = true
logger:i('================')
logger:i('=== Bis Bald ===')
logger:i('================')
logger:i('')
elseif (eventType == hs.caffeinate.watcher.screensDidUnlock) then
Cafe.isLocked = false
elseif (eventType == hs.caffeinate.watcher.screensDidLock) then
Cafe.isLocked = true
end
end
Cafe.watcher = hs.caffeinate.watcher.new(Cafe.cafeHandler)
Cafe.watcher:start()