-
Notifications
You must be signed in to change notification settings - Fork 6
/
peek.lua
109 lines (94 loc) · 3.22 KB
/
peek.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function peekAtApp(appString)
local app = hs.application.get(appString)
if app == nil then
hs.application.open(appString)
return
end
if app:isRunning() then
if app:isFrontmost() then
app:hide()
else
hs.application.open(appString)
app:activate()
end
else
hs.application.open(app)
end
end
function peekButtonFor(bundleID)
return {
['name'] = "Peek " .. bundleID,
['image'] = hs.image.imageFromAppBundle(bundleID),
['onClick'] = function()
peekAtApp(bundleID)
end,
['onLongPress'] = function(holding)
peekAtApp(bundleID)
end
}
end
local calendarButtonDimension = 76
function calendarPeekButton()
local button = peekButtonFor('com.apple.iCal')
local x = (buttonWidth - calendarButtonDimension)/2
local y = (buttonHeight - calendarButtonDimension)/2
local radius = 16
local headerHeight = 24
local headerFontSize = 16
local bodyFontSize = 42
local headerText = os.date("%b")
-- +0 to strip leading 0
local bodyText = os.date("%d") + 0
button['image'] = nil
button['stateProvider'] = function()
return os.date("%d") + 0
end
button['imageProvider'] = function(state)
local elements = {}
-- White background
table.insert(elements, {
action = "fill",
frame = { x = x, y = y, w = calendarButtonDimension, h = calendarButtonDimension },
fillColor = hs.drawing.color.white,
type = "rectangle",
})
-- Red header
table.insert(elements, {
action = "fill",
frame = { x = x, y = y, w = calendarButtonDimension, h = headerHeight },
fillColor = { red = 249.0/255.0, green = 86.0/255.0, blue = 78.0/255.0, alpha = 1.0},
type = "rectangle"
})
-- Header text
table.insert(elements, {
frame = { x = x, y = y, w = calendarButtonDimension, h = headerHeight },
text = hs.styledtext.new(headerText, {
font = { name = ".AppleSystemUIFont", size = headerFontSize },
paragraphStyle = { alignment = "center" },
color = hs.drawing.color.white,
}),
type = "text"
})
-- Body text
table.insert(elements, {
frame = { x = x, y = y + headerHeight, w = calendarButtonDimension, h = calendarButtonDimension - headerHeight },
text = hs.styledtext.new(bodyText, {
font = { name = ".AppleSystemUIFont", size = bodyFontSize },
paragraphStyle = { alignment = "center" },
color = hs.drawing.color.black,
}),
type = "text"
})
-- Clip
-- This doesn't work, and I don't know why
table.insert(elements, {
action = "clip",
frame = { x = x, y = y, w = calendarButtonDimension, h = calendarButtonDimension },
roundedRectRadii = { xRadius = radius, yRadius = radius },
type = "rectangle",
})
return streamdeck_imageWithCanvasContents(elements)
end
button['updateInterval'] = 10
return button
end