File indexing completed on 2024-12-22 05:15:15
0001 /* 0002 SPDX-FileCopyrightText: 2011 Sebastian Kügler <sebas@kde.org> 0003 SPDX-FileCopyrightText: 2012 Viranch Mehta <viranch.mehta@gmail.com> 0004 SPDX-FileCopyrightText: 2014-2016 Kai Uwe Broulik <kde@privat.broulik.de> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 function stringForBatteryState(batteryData, source) { 0010 if (batteryData["Plugged in"]) { 0011 // When we are using a charge threshold, the kernel 0012 // may stop charging within a percentage point of the actual threshold 0013 // and this is considered correct behavior, so we have to handle 0014 // that. See https://bugzilla.kernel.org/show_bug.cgi?id=215531. 0015 if (typeof source.data["Battery"]["Charge Stop Threshold"] === "number" 0016 && (source.data.Battery.Percent >= source.data["Battery"]["Charge Stop Threshold"] - 1 0017 && source.data.Battery.Percent <= source.data["Battery"]["Charge Stop Threshold"] + 1) 0018 // Also, Upower may give us a status of "Not charging" rather than 0019 // "Fully charged", so we need to account for that as well. See 0020 // https://gitlab.freedesktop.org/upower/upower/-/issues/142. 0021 && (source.data["Battery"]["State"] === "NoCharge" || source.data["Battery"]["State"] === "FullyCharged") 0022 ) { 0023 return i18n("Fully Charged"); 0024 } 0025 0026 // Otherwise, just look at the charge state 0027 switch(batteryData["State"]) { 0028 case "Discharging": return i18n("Discharging"); 0029 case "FullyCharged": return i18n("Fully Charged"); 0030 case "Charging": return i18n("Charging"); 0031 // when in doubt we're not charging 0032 default: return i18n("Not Charging"); 0033 } 0034 } else { 0035 return i18nc("Battery is currently not present in the bay", "Not present"); 0036 } 0037 } 0038 0039 function updateInhibitions(rootItem, source) { 0040 const inhibitions = []; 0041 const manualInhibitions = []; 0042 0043 if (source.data["Inhibitions"]) { 0044 for (let key in pmSource.data["Inhibitions"]) { 0045 if (key === "plasmashell" || key === "plasmoidviewer") { 0046 manualInhibitions.push(key); 0047 } else { 0048 inhibitions.push(pmSource.data["Inhibitions"][key]); 0049 } 0050 } 0051 } 0052 0053 rootItem.manuallyInhibited = manualInhibitions.length > 0; 0054 rootItem.inhibitions = inhibitions; 0055 }