icons & tweaks
This commit is contained in:
parent
c36eb8daae
commit
de0ae352cb
@ -1,22 +1,25 @@
|
||||
const colors = [
|
||||
'#f00', '#e21c00', '#c83800', '#a50', '#8d7100',
|
||||
'#718d00', '#6fa100', '#5c8000', '#498000', '#080'
|
||||
];
|
||||
|
||||
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;
|
||||
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";
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user