headsetcontrol-battery-widget/package/contents/ui/lib/helper.js

20 lines
536 B
JavaScript
Raw Normal View History

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