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: 'HH:mm:ss MMM月d日 EEE', locale: 'zh-CN' }, battery: { type: 'battery' }, memory: { type: 'memory' }, weather: { type: 'weather' }, }); function getNetworkIcon(networkOutput) { switch (networkOutput.defaultInterface?.type) { case 'ethernet': return ; case 'wifi': if (networkOutput.defaultGateway?.signalStrength >= 80) { return ; } else if ( networkOutput.defaultGateway?.signalStrength >= 65 ) { return ; } else if ( networkOutput.defaultGateway?.signalStrength >= 40 ) { return ; } else if ( networkOutput.defaultGateway?.signalStrength >= 25 ) { return ; } else { return ; } default: return ( ); } } // Get icon to show for how much of the battery is charged. function getBatteryIcon(batteryOutput) { if (batteryOutput.chargePercent > 90) return ; if (batteryOutput.chargePercent > 70) return ; if (batteryOutput.chargePercent > 40) return ; if (batteryOutput.chargePercent > 20) return ; return ; } // Get icon to show for current weather status. function getWeatherIcon(weatherOutput) { switch (weatherOutput.status) { case 'clear_day': return ; case 'clear_night': return ; case 'cloudy_day': return ; case 'cloudy_night': return ; case 'light_rain_day': return ; case 'light_rain_night': return ; case 'heavy_rain_day': return ; case 'heavy_rain_night': return ; case 'snow_day': return ; case 'snow_night': return ; case 'thunder_day': return ; case 'thunder_night': return ; } } createRoot(document.getElementById('root')).render(); function App() { const [output, setOutput] = useState(providers.outputMap); useEffect(() => { providers.onOutput(() => setOutput(providers.outputMap)); }, []); return (
{output.glazewm && (
{output.glazewm.currentWorkspaces.map(workspace => ( ))}
)}
{output.date?.formatted}
{output.glazewm && ( <> {output.glazewm.bindingModes.map(bindingMode => ( ))} )} {output.network && (
{getNetworkIcon(output.network)} {output.network.defaultGateway?.ssid}
)} {output.memory && (
{Math.round(output.memory.usage)}%
)} {output.cpu && (
{/* Change the text color if the CPU usage is high. */} 85 ? 'high-usage' : ''} > {Math.round(output.cpu.usage)}%
)} {output.battery && (
{/* Show icon for whether battery is charging. */} {output.battery.isCharging && ( )} {getBatteryIcon(output.battery)} {Math.round(output.battery.chargePercent)}%
)} {output.weather && (
{getWeatherIcon(output.weather)} {Math.round(output.weather.celsiusTemp)}°C
)}
); }