outsource lib
This commit is contained in:
parent
d51555ee47
commit
ecf5c67ffb
22
package/contents/ui/lib/helper.js
Normal file
22
package/contents/ui/lib/helper.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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)]; break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
function batteryLevel(batteryPercent) {
|
||||
if(batteryPercent == -1)
|
||||
return "charging";
|
||||
else if(batteryPercent == -2)
|
||||
return "not connected";
|
||||
else
|
||||
return batteryPercent + "%";
|
||||
}
|
|
@ -4,6 +4,8 @@ import org.kde.plasma.plasmoid 2.0
|
|||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.kirigami 2.14 as Kirigami
|
||||
|
||||
import "./lib/helper.js" as Helper
|
||||
|
||||
Item {
|
||||
id: main
|
||||
|
||||
|
@ -39,7 +41,7 @@ Item {
|
|||
color: "transparent"
|
||||
border.color: PlasmaCore.Theme.textColor
|
||||
radius: 4
|
||||
Plasmoid.toolTipMainText: "battery level: " + batteryLevel()
|
||||
Plasmoid.toolTipMainText: "battery level: " + Helper.batteryLevel(batteryPercent)
|
||||
Plasmoid.toolTipSubText: "polling rate: " + pollingrate + " seconds"
|
||||
|
||||
Item {
|
||||
|
@ -49,7 +51,7 @@ Item {
|
|||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
color: batteryColor()
|
||||
color: Helper.batteryColor(batteryPercent)
|
||||
width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100
|
||||
}
|
||||
Kirigami.Icon { // headphones icon
|
||||
|
|
Loading…
Reference in New Issue
Block a user