-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
208 lines (161 loc) · 4.17 KB
/
index.coffee
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#############################################################################
# Customization
#############################################################################
bar =
width: "100%"
height: 27 # Text vertically aligns best with odd heights
gap:
left: 23
right: 17
top: 10
font:
color: "#999"
background:
color: "rgba(255, 255, 255, 0.9)"
border:
radius: 1
color: "000"
padding: "0 10px"
# Order represents priority
playing:
spotify: ""
youtube: ""
soundcloud: ""
sonos: ""
# Time format
time: "%l:%M:%S"
# Date Format
date: "%a %d %b"
#############################################################################
style: """
width: calc(#{bar.width} - #{bar.gap.left * 2 + bar.gap.right}px)
height: #{bar.height}px
left: #{bar.gap.left}px
top: #{bar.gap.top}px
color: #{bar.font.color}
background-color: #{bar.background.color}
padding: #{bar.padding}
z-index: 20
border-radius: #{bar.border.radius}px;
border-color: #{bar.border.color}
-webkit-box-shadow: 0px 2px 15px 0px rgba(107,107,107,0.11);
box-shadow: 0px 9px 15px 0px rgba(107,107,107,0.5)
font-size: 14px
font-family: 'Helvetica'
div
display: inline-block
height: #{bar.height}px
line-height: #{bar.height}px
span
vertical-align: middle
line-height: normal
.left
float: left
.right
float: right
padding-left: 15px
.focused
color: #999
.center
position: absolute
left: 0
width: 100%
text-align: center
.playing
.icon
padding: 0 3px
.fa-spotify
color: #2fd566
.fa-youtube, .fa-youtube-play
color: #e62117
.fa-soundcloud
color: #f50
font-size: 18px
.battery
.icon
margin-left: 3px
.fa-battery-empty
color: red
.icon
font-size: 16px
"""
command: "#{process.argv[0]} bar/commands/update.js"
refreshFrequency: 1000 # ms
render: (output) ->
@run("bar/install")
"""
<link rel="stylesheet" href="bar/assets/font-awesome/css/font-awesome.min.css" />
<div class='left focused'>
<span></span>
</div>
<div class='right time'>
<span></span>
</div>
<div class='right date'>
<span></span>
</div>
<div class='right battery'>
<span></span>
<span class="icon"></span>
</div>
<div class='center playing'>
<span class="icon"></span>
<span></span>
</div>
"""
update: (output, el) ->
data = JSON.parse(output)
@addFocused(data.active, el)
@addTime(data.time, el)
@addDate(data.date, el)
@addBattery(data.battery, el)
@addPlaying(data, el)
addFocused: (focused, el) ->
$(".focused span", el).text(focused)
addDate: (date, el) ->
$(".date span", el).text(date)
addTime: (time, el) ->
$(".time span, el").text(time)
addBattery: (battery, el) ->
battery = parseInt(battery)
$(".battery span:first-child", el).text("#{battery}%")
$icon = $(".battery span.icon", el)
$icon.removeClass().addClass("icon")
$icon.addClass("fa #{@batteryIcon(battery)}")
addPlaying: (music, el) ->
@source ||= {}
# DOM handles
$icon = $(".playing span.icon")
$playing = $(".playing span:last-child", el)
playing = { track: "", source: "", icon: "" }
if music.spotify and music.spotify.playing
playing.track = music.spotify.track
playing.icon = @playingIcon(music.spotify.source)
playing.source = music.spotify.source
else if music.browser and music.browser.playing
playing.track = music.browser.track
playing.icon = @playingIcon(music.browser.source)
playing.source = music.browser.source
# Current source has changed
if @source != playing.source
$icon.removeClass().addClass("icon")
$icon.addClass("fa fa-#{playing.icon}")
$playing.text(playing.track)
@source = music.source
batteryIcon: (percentage) =>
return if percentage > 90
"fa-battery-full"
else if percentage > 70
"fa-battery-three-quarters"
else if percentage > 40
"fa-battery-half"
else if percentage > 20
"fa-battery-quarter"
else
"fa-battery-empty"
playingIcon: (source) =>
return switch source
when "youtube" then "youtube-play"
when "soundcloud" then "soundcloud"
when "spotify" then "spotify"
else ""