1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-26 22:42:50 -05:00

Add battery charge limit (#1151)

This commit is contained in:
Aaron Tulino
2025-12-25 10:09:09 -07:00
committed by GitHub
parent 6b6f51cd1f
commit adf92cbc46
6 changed files with 51 additions and 3 deletions

View File

@@ -12,6 +12,8 @@ Singleton {
property bool suppressSound: true
property bool previousPluggedState: false
readonly property var scale: 100 / SettingsData.batteryChargeLimit
Timer {
id: startupTimer
interval: 500
@@ -43,14 +45,14 @@ Singleton {
return 0;
if (batteryCapacity === 0) {
if (usePreferred && device && device.ready)
return Math.round(device.percentage * 100);
return Math.round(device.percentage * 100 * scale);
const validBatteries = batteries.filter(b => b.ready && b.percentage >= 0);
if (validBatteries.length === 0)
return 0;
const avgPercentage = validBatteries.reduce((sum, b) => sum + b.percentage, 0) / validBatteries.length;
return Math.round(avgPercentage * 100);
return Math.round(avgPercentage * 100 * scale);
}
return Math.round((batteryEnergy * 100) / batteryCapacity);
return Math.round((batteryEnergy * 100) / batteryCapacity * scale);
}
readonly property bool isCharging: batteryAvailable && batteries.some(b => b.state === UPowerDeviceState.Charging)