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
47
48
|
-- ==========================================
-- SMART GLASSES HUD
-- Modulo de notificacoes
-- ==========================================
local notifications = {}
function notifications.init(context)
context.data.notifications = {}
print("Modulo de notificacoes iniciado!")
end
function notifications.add(context, mensagem, tipo)
if not context.config.notifications.enabled then
return
end
local lista = context.data.notifications
lista[#lista + 1] = {
message = tostring(mensagem),
type = tipo or "info",
createdAt = os.clock()
}
local limite = context.config.notifications.maxVisible
while #lista > limite do
table.remove(lista, 1)
end
end
function notifications.update(context)
local lista = context.data.notifications
local duracao = context.config.notifications.duration
local agora = os.clock()
for i = #lista, 1, -1 do
local item = lista[i]
if agora - item.createdAt >= duracao then
table.remove(lista, i)
end
end
end
return notifications
|