-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
225 lines (202 loc) · 8.2 KB
/
Copy pathindex.html
File metadata and controls
225 lines (202 loc) · 8.2 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Base styles for better consistency across platforms (aka. CSS reset). -->
<link rel="stylesheet" type="text/css" href="../normalize.css" />
<!-- Custom styles. -->
<link rel="stylesheet" type="text/css" href="./styles.css" />
<!-- Font Awesome Icons. -->
<script src="https://kit.fontawesome.com/fdd6886a98.js" crossorigin="anonymous"></script>
<!-- Add empty favicon to suppress not found errors. -->
<link rel="icon" href="data:;" />
<!-- Allows React to be run buildless via "text/babel" script below. -->
<script
src="https://unpkg.com/@babel/standalone@7.25.6/babel.min.js"
integrity="sha256-aS0B0wnsaDByLfE16h4MDCP1fQFccysd1YWOcV+gbBo="
crossorigin="anonymous"
></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel" data-type="module">
import React, {
useState,
useEffect,
} from 'https://esm.sh/react@18?dev';
import { createRoot } from 'https://esm.sh/react-dom@18/client?dev';
import * as zebar from 'https://esm.sh/zebar@2';
const providers = zebar.createProviderGroup({
network: { type: 'network' },
glazewm: { type: 'glazewm' },
cpu: { type: 'cpu' },
date: { type: 'date', formatting: 'EEE d MMM T' },
battery: { type: 'battery' },
memory: { type: 'memory' },
weather: { type: 'weather' },
});
createRoot(document.getElementById('root')).render(<App />);
function App() {
const [output, setOutput] = useState(providers.outputMap);
useEffect(() => {
providers.onOutput(() => setOutput(providers.outputMap));
}, []);
// Get icon to show for current network status.
function getNetworkIcon(networkOutput) {
switch (networkOutput.defaultInterface?.type) {
case 'ethernet':
return <i class="fa-solid fa-network-wired"></i>;
case 'wifi':
if (networkOutput.defaultGateway?.signalStrength >= 80) {
return <i className="nf nf-md-wifi_strength_4"></i>;
} else if (
networkOutput.defaultGateway?.signalStrength >= 65
) {
return <i className="nf nf-md-wifi_strength_3"></i>;
} else if (
networkOutput.defaultGateway?.signalStrength >= 40
) {
return <i className="nf nf-md-wifi_strength_2"></i>;
} else if (
networkOutput.defaultGateway?.signalStrength >= 25
) {
return <i className="nf nf-md-wifi_strength_1"></i>;
} else {
return <i className="nf nf-md-wifi_strength_outline"></i>;
}
default:
return (
<i className="nf nf-md-wifi_strength_off_outline"></i>
);
}
}
// Get icon to show for how much of the battery is charged.
function getBatteryIcon(batteryOutput) {
if (batteryOutput.chargePercent > 90)
return <i class="fa-solid fa-battery-full"></i>;
if (batteryOutput.chargePercent > 70)
return <i class="fa-solid fa-battery-three-quarters"></i>;
if (batteryOutput.chargePercent > 40)
return <i class="fa-solid fa-battery-half"></i>;
if (batteryOutput.chargePercent > 20)
return <i class="fa-solid fa-battery-quarter"></i>;
return <i class="fa-solid fa-battery-empty"></i>;
}
// Get icon to show for current weather status.
function getWeatherIcon(weatherOutput) {
switch (weatherOutput.status) {
case 'clear_day':
return <i class="fa-solid fa-sun"></i>;
case 'clear_night':
return <i class="fa-solid fa-moon"></i>;
case 'cloudy_day':
return <i class="fa-solid fa-cloud-sun"></i>;
case 'cloudy_night':
return <i class="fa-solid fa-cloud-moon"></i>;
case 'light_rain_day':
return <i class="fa-solid fa-cloud-sun-rain"></i>;
case 'light_rain_night':
return <i class="fa-solid fa-cloud-moon-rain"></i>;
case 'heavy_rain_day':
return <i class="fa-solid fa-cloud-showers-heavy"></i>;
case 'heavy_rain_night':
return <i class="fa-solid fa-cloud-showers-heavy"></i>;
case 'snow_day':
return <i class="fa-solid fa-snowflake"></i>;
case 'snow_night':
return <i class="fa-solid fa-snowflake"></i>;
case 'thunder_day':
return <i class="fa-solid fa-cloud-bolt"></i>;
case 'thunder_night':
return <i class="fa-solid fa-cloud-bolt"></i>;
}
}
return (
<div className="app">
<div className="left">
<i class="fa-solid fa-robot"></i>
{output.glazewm && (
<div className="workspaces">
{output.glazewm.currentWorkspaces.map(workspace => (
<button
className={`workspace ${workspace.hasFocus && 'focused'} ${workspace.isDisplayed && 'displayed'}`}
onClick={() =>
output.glazewm.runCommand(
`focus --workspace ${workspace.name}`,
)
}
key={workspace.name}
>
{workspace.displayName ?? workspace.name}
</button>
))}
</div>
)}
</div>
<div className="center">{output.date?.formatted}</div>
<div className="right">
{output.glazewm && (
<>
{output.glazewm.bindingModes.map(bindingMode => (
<button
className="binding-mode"
key={bindingMode.name}
>
{bindingMode.displayName ?? bindingMode.name}
</button>
))}
<button
className={`tiling-direction nf ${output.glazewm.tilingDirection === 'horizontal' ? 'fa-solid fa-arrows-left-right' : 'fa-solid fa-arrows-up-down'}`}
onClick={() =>
output.glazewm.runCommand('toggle-tiling-direction')
}
></button>
</>
)}
{output.network && (
<div className="network">
{getNetworkIcon(output.network)}
{output.network.defaultGateway?.ssid}
</div>
)}
{output.memory && (
<div className="memory">
<i class="fa-solid fa-memory"></i>
{Math.round(output.memory.usage)}%
</div>
)}
{output.cpu && (
<div className="cpu">
<i class="fa-solid fa-microchip"></i>
{/* Change the text color if the CPU usage is high. */}
<span
className={output.cpu.usage > 85 ? 'high-usage' : ''}
>
{Math.round(output.cpu.usage)}%
</span>
</div>
)}
{output.battery && (
<div className="battery">
{/* Show icon for whether battery is charging. */}
{output.battery.isCharging && (
<i class="fa-solid fa-plug"></i>
)}
{getBatteryIcon(output.battery)}
{Math.round(output.battery.chargePercent)}%
</div>
)}
{output.weather && (
<div className="weather">
{getWeatherIcon(output.weather)}
{Math.round(output.weather.celsiusTemp)}°C
</div>
)}
</div>
</div>
);
}
</script>
</body>
</html>