-
Notifications
You must be signed in to change notification settings - Fork 5
/
info.coffee
164 lines (137 loc) · 6.07 KB
/
info.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
#
# ──────────────────────────────────────────────── II ──────
# :::::: I N F O : : : : : : : :
# ──────────────────────────────────────────────────────────
#
#
# ─── ALL COMMANDS ───────────────────────────────────────────────────────────
#
commands =
battery: "pmset -g batt | egrep '([0-9]+\%).*' -o --colour=auto " +
"| cut -f1 -d';'"
time: "date +\"%H:%M\""
wifi: "/System/Library/PrivateFrameworks/Apple80211.framework/" +
"Versions/Current/Resources/airport -I | " +
"sed -e \"s/^ *SSID: //p\" -e d"
volume: "osascript -e 'output volume of (get volume settings)'"
charging: "pmset -g batt"
#
# ─── COLORS ─────────────────────────────────────────────────────────────────
#
colors =
black: "#1d2021"
grey: "#a89984"
red: "#fb4924"
green: "#b8bb26"
yellow: "#fabd2f"
blue: "#458588"
magenta: "#b16286"
cyan: "#689d6a"
white: "#ebdbb2"
#
# ─── COMMAND ────────────────────────────────────────────────────────────────
#
command: "echo " +
"$(#{ commands.battery }):::" +
"$(#{ commands.time }):::" +
"$(#{ commands.wifi }):::" +
"$(#{ commands.volume }):::" +
"$(#{ commands.charging }):::"
#
# ─── REFRESH ────────────────────────────────────────────────────────────────
#
refreshFrequency: 1000
#
# ─── RENDER ─────────────────────────────────────────────────────────────────
#
render: ( ) ->
"""
<link rel="stylesheet" href="./font-awesome/font-awesome.min.css" />
<div class="info-item volume">
<div class="icon"><span class="volume-icon"></span></div>
<span class="volume-output"></span>
</div>
<div class="info-item wifi">
<div class="icon"><i class="fa fa-wifi"></i></div>
<span class="wifi-output"></span>
</div>
<div class="info-item battery">
<div class="icon"><span class="battery-icon"></span></div>
<span class="battery-output"></span>
</div>
<div class="info-item time">
<div class="icon"><i class="fa fa-clock-o"></i></div>
<span class="time-output"></span>
</div>
"""
#
# ─── RENDER ─────────────────────────────────────────────────────────────────
#
update: ( output ) ->
output = output.split( /:::/g )
battery = output[ 0 ]
time = output[ 1 ]
wifi = output[ 2 ]
volume = output[ 3 ]
charging = output[ 4 ]
$( ".battery-output" ) .text( "#{ battery }" )
$( ".time-output" ) .text( "#{ time }" )
$( ".wifi-output" ) .text( "#{ wifi }" )
$( ".volume-output" ) .text( "#{ volume }%" )
@handleBattery(
Number( battery.replace( /%/g, "" ) ),
!charging.indexOf( "discharging" ) >= 0
)
@handleVolume( Number( volume ) )
#
# ─── HANDLE BATTERY ─────────────────────────────────────────────────────────
#
handleBattery: ( percentage, charging ) ->
batteryIcon = switch
when charging then "fa-bolt"
when percentage <= 12 then "fa-battery-0"
when percentage <= 25 then "fa-battery-1"
when percentage <= 50 then "fa-battery-2"
when percentage <= 75 then "fa-battery-3"
when percentage <= 100 then "fa-battery-4"
$( ".battery-icon" ).html( "<i class=\"fa #{ batteryIcon }\"></i>" )
color = if percentage < 25 then colors.red else colors.green
$( ".battery .icon" ).css( "background-color", color )
#
# ─── HANDLE VOLUME ──────────────────────────────────────────────────────────
#
handleVolume: ( volume ) ->
volumeIcon = switch
when volume == 0 then "fa-volume-off"
when volume <= 50 then "fa-volume-down"
when volume <= 100 then "fa-volume-up"
$( ".volume-icon" ).html( "<i class=\"fa #{ volumeIcon }\"></i>" )
#
# ─── STYLE ──────────────────────────────────────────────────────────────────
#
style: """
.battery .icon
background-color: #{ colors.green }
.time .icon
background-color: #{ colors.magenta }
.wifi .icon
background-color: #{ colors.grey }
.volume .icon
background-color: #{ colors.cyan }
.info-item
display: flex
padding: 0 5px 0 0
background-color: #{ colors.white }
margin-right: 15px
.icon
padding: 1px 5px
margin-right: 5px
display: flex
top: 3.5px
right: 0px
font-family: 'Fira Code'
font-size: 13px
font-smoothing: antialiasing
z-index: 0
"""
# ──────────────────────────────────────────────────────────────────────────────