-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.lua
More file actions
46 lines (34 loc) · 886 Bytes
/
cache.lua
File metadata and controls
46 lines (34 loc) · 886 Bytes
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
return function(ctx)
local cache = {}
cache.TTL = ctx.cache_ttl or 60
cache.timer = {}
cache.timers = {}
cache.frames = {}
local function timerCreator(cb)
return hs.timer.delayed.new(cache.TTL, cb)
end
function cache.timer:start(id)
if (not cache.timers[id]) then
cache.timers[id] = timerCreator(function()
cache.frames[id] = nil
end)
end
cache.timers[id]:start()
end
function cache:set(win)
local win = win or hs.window.focusedWindow()
if (not win) or (not win:id()) then return end
self.frames[win:id()] = win:frame()
cache.timer:start(win:id())
end
function cache:clear()
self.frames = {}
-- Stop all timers, if they are running
-- Remove hs.timer.delay object
for id,timer in pairs(self.timers) do
timer:stop()
self.timers[id] = nil
end
end
return cache
end