You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
919 B

class Battery {
constructor() {
this._battery = document.querySelector("#battery-label")
this._info = {}
this._init()
}
_updateData() {
this._info = lightdm.batteryData
var level = this._info.level
var state = this._info.state
var icon = 0
var charging = ""
var blevel = Math.floor(level / 10) * 10
icon = `-${blevel}`
charging = state == "Charging" ? "-charging" : ""
if (blevel < 10) icon = "-outline"
if (state == "Full" ) { icon = ""; charging = ""}
if (level >= 0) {
this._battery.style.visibility = "visible"
this._battery.innerHTML = `<span class="mdi mdi-battery${charging}${icon}"></span> ${level}%`
} else {
this._battery.innerHTML = ""
this._battery.style.visibility = "hidden"
}
}
_setTimer() {
if (!lightdm.can_access_battery) return
this._updateData()
}
_init() {
this._setTimer()
}
}