VulpesOS/gaia/apps/system/js/battery_icon.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

49 lines
1.3 KiB
JavaScript
Executable file

/* global BaseIcon */
'use strict';
(function(exports) {
var BatteryIcon = function(manager) {
BaseIcon.call(this, manager);
};
BatteryIcon.prototype = Object.create(BaseIcon.prototype);
BatteryIcon.prototype.name = 'BatteryIcon';
BatteryIcon.prototype.update = function() {
if (!this.element) {
return;
}
this.show();
var battery = this.manager._battery;
var icon = this.element;
var previousLevel = parseInt(icon.dataset.level, 10);
var previousCharging = (icon.dataset.charging === 'true');
icon.dataset.charging = battery.charging;
var level = Math.floor(battery.level * 10) * 10;
this.debug('previous level: ', previousLevel);
this.debug('current level:', level);
if (previousLevel === level &&
previousCharging === battery.charging) {
return;
}
icon.dataset.level = level;
navigator.mozL10n.setAttributes(
icon,
battery.charging ? 'statusbarBatteryCharging' : 'statusbarBattery',
{level: level}
);
this.previousCharging = battery.charging;
this.publish('changed');
};
BatteryIcon.prototype.view = function view() {
return `<div id="statusbar-battery"
class="sb-icon sb-icon-battery"
role="listitem">
</div>`;
};
exports.BatteryIcon = BatteryIcon;
}(window));