This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.coffee
137 lines (120 loc) · 4.37 KB
/
status.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
command: './scripts/status.py'
refreshFrequency: 10000 # ms
render: (output) ->
"""
<div class="compstatus"></div>
"""
style: """
right: 28px
top: 2px
height: 13
.wifi
font: 14px FontAwesome
top: 1px
position: relative
left: 10px
.charging
font: 12px FontAwesome
position: relative
top: 0px
right: -12px
z-index: 1
"""
timeAndDate: (date, time) ->
# returns a formatted html string with the date and time
return "<span class='white'><span class='icon'>  </span>#{date} <span> ⎢ </span><span class='icon'> </span>#{time}</span></span>";
batteryStatus: (battery, state) ->
#returns a formatted html string current battery percentage, a representative icon and adds a lighting bolt if the
# battery is plugged in and charging
# If no battery exists, battery is only '%' character
if state == 'AC' and battery == "%"
return "<span class='green icon'></span>"
batnum = parseInt(battery)
if state == 'AC' and batnum >= 90
return "<span class='charging yellow outline_icon sicon'></span><span class='green icon '></span> <span class='white'>#{batnum}%</span>"
else if state == 'AC' and batnum >= 50 and batnum < 90
return "<span class='charging yellow outline_icon icon'></span><span class='green icon'></span> <span class='white'>#{batnum}%</span>"
else if state == 'AC' and batnum < 50 and batnum >= 15
return "<span class='charging yellow outline_icon icon'></span><span class='yellow icon'></span> <span class='white'>#{batnum}%</span>"
else if state == 'AC' and batnum < 15
return "<span class='charging yellow icon'></span><span class='red icon'></span> <span class='white'>#{batnum}%</span>"
else if batnum >= 90
return "<span class='green icon'> </span> <span class='white'>#{batnum}%</span>"
else if batnum >= 50 and batnum < 90
return "<span class='green icon'> </span> <span class='white'>#{batnum}%</span>"
else if batnum < 50 and batnum >= 25
return "<span class='yellow icon'> </span> <span class='white'>#{batnum}%</span>"
else if batnum < 25 and batnum >= 15
return "<span class='yellow icon'> </span> <span class='white'>#{batnum}%</span>"
else if batnum < 15
return "<span class='red icon'> </span> <span class='white'>#{batnum}%</span>"
getWifiStatus: (status, netName, netIP) ->
if status == "Wi-Fi"
return "<span class='wifi '>    </span><span class='white'>#{netName} </span>"
if status == 'USB 10/100/1000 LAN' or status == 'Apple USB Ethernet Adapter'
return "<span class='wifi '>    </span><span class='white'>#{netIP}</span>"
else
return "<span class='grey wifi'>   </span><span class='white'>--   </span>"
getVolume: (str) ->
if str == "0"
return "<span class='volume'> </span>"
else
return "<span class='volume'> </span><span class='white'>#{str} </span>"
getCurrentTime: () ->
today = new Date
hours = today.getHours()
minutes = today.getMinutes()
if minutes < 10
minutes = '0' + minutes
if hours < 10
hours = '0' + hours
time = hours + ':' + minutes
return time
getCurrentDate: () ->
today = new Date
daylist = [
'Sun'
'Mon'
'Tue'
'Wed'
'Thu'
'Fri'
'Sat'
]
month_list = [
'Jan'
'Feb'
'Mar'
'Apr'
'May'
'Jun'
'Jul'
'Aug'
'Sep'
'Oct'
'Nov'
'Dec'
]
day = daylist[today.getDay()]
date = today.getDate()
month = month_list[today.getMonth()]
year = today.getYear() + 1900
output=day + ', ' + month + ' ' + date + ' ' + year
return output
update: (output, domEl) ->
# split the output of the script
values = output.split('@')
time = @getCurrentTime()
date = @getCurrentDate()
battery = values[0]
isCharging = values[1]
netStatus = values[2].replace /^\s+|\s+$/g, ""
netName = values[3]
netIP = values[4]
volume = values[5]
# create an HTML string to be displayed by the widget
htmlString = @getVolume(volume) + "<span>" + " ⎢" + "</span>" +
@getWifiStatus(netStatus, netName, netIP) + "<span>" + " ⎢ " + "</span>" +
@batteryStatus(battery, isCharging) + "<span>" + " ⎢ " + "</span>" +
@timeAndDate(date,time)
$(domEl).find('.compstatus').html(htmlString)