icons & tweaks

This commit is contained in:
Flummi 2024-01-20 04:49:58 +01:00
parent c36eb8daae
commit de0ae352cb
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
2 changed files with 24 additions and 23 deletions

View File

@ -1,22 +1,25 @@
function batteryColor(batteryPercent) {
const colors = [
'#f00', '#e21c00', '#c83800', '#a50', '#8d7100',
'#718d00', '#6fa100', '#5c8000', '#498000', '#080'
];
let color;
switch(batteryPercent) {
case -1: color = "green"; break;
case -2: color = "red"; break;
default: color = colors[~~(batteryPercent / 10 + 0.5) - 1]; break;
}
return color;
function batteryColor(batteryPercent) {
return colors[({
"-2": 9,
"-1": 0
})[batteryPercent] ?? ~~(batteryPercent / 10 + 0.5) - 1];
}
function batteryLevel(batteryPercent) {
if(batteryPercent == -1)
return "charging";
else if(batteryPercent == -2)
return "not connected";
else
return batteryPercent + "%";
return ({
"-2": "not connected",
"-1": "charging"
})[batteryPercent] ?? batteryPercent + "%";
}
function batteryIcon(batteryPercent) {
return ({
"-2": "action-unavailable",
"-1": "battery-ac-adapter"
})[batteryPercent] ?? "audio-headphones-symbolic";
}

View File

@ -18,11 +18,9 @@ Item {
connectedSources: ["headsetcontrol -bc"]
interval: pollingrate * 1e3
onNewData: {
if(data['exit code'] > 0) {
batteryPercent = -2;
return;
}
batteryPercent = data['stdout'];
return batteryPercent = data['exit code'] > 0
? -2 // not connected
: data['stdout'];
}
}
@ -60,7 +58,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 1
anchors.bottomMargin: 1
source: "audio-headphones-symbolic"
source: Helper.batteryIcon(batteryPercent)
}
}
}