headsetcontrol-battery-widget/package/contents/ui/lib/helper.js
2024-01-20 04:55:08 +01:00

20 lines
536 B
JavaScript

const colors = [
'#f00', '#e21c00', '#c83800', '#a50', '#8d7100',
'#718d00', '#6fa100', '#5c8000', '#498000', '#080'
];
const batteryColor = batteryPercent => colors[({
"-2": 9,
"-1": 0
})[batteryPercent] ?? ~~(batteryPercent / 10 + 0.5) - 1];
const batteryLevel = batteryPercent => ({
"-2": "not connected",
"-1": "charging"
})[batteryPercent] ?? batteryPercent + "%";
const batteryIcon = batteryPercent => ({
"-2": "action-unavailable",
"-1": "battery-ac-adapter"
})[batteryPercent] ?? "audio-headphones-symbolic";