2024-02-25 19:19:48 -05:00
|
|
|
|
|
|
|
const { Box, Icon, Label } = Widget;
|
2024-02-25 12:10:05 -05:00
|
|
|
|
|
|
|
const RAZER_POLL = 30000;
|
|
|
|
const LOW_BATT = 20;
|
|
|
|
|
|
|
|
|
2024-02-25 19:19:48 -05:00
|
|
|
// TODO: add charging indicator
|
2024-02-25 12:10:05 -05:00
|
|
|
const RazerBat = Variable(-1, {
|
|
|
|
poll: [
|
|
|
|
RAZER_POLL,
|
|
|
|
[
|
|
|
|
'bash',
|
|
|
|
'-c',
|
|
|
|
"polychromatic-cli -n 'Razer Naga Pro (Wired)' -k" +
|
|
|
|
' || ' +
|
|
|
|
"polychromatic-cli -n 'Razer Naga Pro (Wireless)' -k",
|
|
|
|
],
|
|
|
|
(out) => {
|
2024-02-25 19:19:48 -05:00
|
|
|
const batteryMatches = out.split('\n')
|
2024-02-25 12:10:05 -05:00
|
|
|
.filter((i) => i.includes('Battery'))[0]
|
|
|
|
.match(/[0-9]+/);
|
|
|
|
|
2024-02-25 19:19:48 -05:00
|
|
|
let battery = batteryMatches !== null ?
|
|
|
|
parseInt(batteryMatches[0]) :
|
|
|
|
-1;
|
|
|
|
|
|
|
|
// Don't set to zero when in sleep mode
|
|
|
|
if (battery === 0 && RazerBat.value > 10) {
|
|
|
|
battery = RazerBat.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return battery;
|
2024-02-25 12:10:05 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
export default () => Box({
|
|
|
|
class_name: 'razer',
|
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
hpack: 'start',
|
|
|
|
icon: RazerBat.bind().transform((v) => {
|
|
|
|
return v > -1 ?
|
|
|
|
'mouse-razer-symbolic' :
|
|
|
|
'content-loading-symbolic';
|
|
|
|
}),
|
|
|
|
setup: (self) => {
|
|
|
|
self.hook(RazerBat, () => {
|
|
|
|
self.toggleClassName(
|
|
|
|
'high',
|
|
|
|
RazerBat.value > 66,
|
|
|
|
);
|
|
|
|
self.toggleClassName(
|
|
|
|
'medium',
|
|
|
|
RazerBat.value > LOW_BATT && RazerBat.value <= 66,
|
|
|
|
);
|
|
|
|
self.toggleClassName(
|
|
|
|
'low',
|
|
|
|
RazerBat.value <= LOW_BATT,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2024-02-25 19:19:48 -05:00
|
|
|
Label({
|
|
|
|
vpack: 'center',
|
|
|
|
label: RazerBat.bind().transform((v) => {
|
|
|
|
return v !== -1 ? `${v}%` : '';
|
|
|
|
}),
|
|
|
|
}),
|
2024-02-25 12:10:05 -05:00
|
|
|
],
|
|
|
|
});
|