Files
hlwm-config/conky-bat/index.js
Thomas Ruoff c0af622d2b couple of changes 😓
2021-11-28 23:49:39 +01:00

40 lines
1.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict';
const linuxBattery = require('linux-battery');
async function run() {
try {
const batteries = await linuxBattery();
batteries.forEach(battery => {
if (battery.powerSupply === 'no') {
return '';
}
const color = battery.warningLevel !== 'none' ? '#ff0000' : '#eee8d5';
let stateSymbol = battery.state === 'charging' ? '↑' : '↓';
switch (battery.state) {
case 'charging':
stateSymbol = '↑';
break;
case 'fully-charged':
stateSymbol = 'F';
break;
case 'discharging':
stateSymbol = '↓';
break;
default:
}
const timeLeft = battery.timeToFull || battery.timeToEmpty || '';
const text = `%{F${color}}${battery.percentage} ${stateSymbol} ${timeLeft}%{F-}`;
process.stdout.write(text);
});
} catch (error) {
console.error(error);
}
}
run();