1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-18 09:05:24 -04:00

feat: port critical battery alert from DankBatteryAlerts plugin (#2664)

* feat: port critical battery alert from DankBatteryAlerts plugin

* ui: shorten notification type labels

* refactor: remove duplicate battery charge limit from Power & Sleep
This commit is contained in:
Huỳnh Thiện Lộc
2026-06-18 09:14:57 +07:00
committed by GitHub
parent 7af530de8f
commit 085ce01da6
5 changed files with 64 additions and 24 deletions
+25 -3
View File
@@ -103,8 +103,10 @@ Singleton {
// Is the system plugged in (Is not running on battery)
readonly property bool isPluggedIn: !UPower.onBattery
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= SettingsData.batteryLowThreshold
readonly property bool isCriticalBattery: batteryAvailable && batteryLevel <= SettingsData.batteryCriticalThreshold
property bool _hasNotifiedLowBattery: false
property bool _hasNotifiedCriticalBattery: false
property bool _hasNotifiedChargeLimit: false
function sendAlert(title, message, isWarning, category) {
@@ -129,15 +131,30 @@ Singleton {
_hasNotifiedChargeLimit = false;
}
if (isCharging || !isLowBattery) {
if (isCharging) {
_hasNotifiedLowBattery = false;
_hasNotifiedCriticalBattery = false;
return;
}
if (!isCharging && isLowBattery) {
// Critical battery check (higher priority)
if (isCriticalBattery) {
if (!_hasNotifiedCriticalBattery && SettingsData.batteryNotifyCritical) {
_hasNotifiedCriticalBattery = true;
sendAlert(I18n.tr("Critical Battery"), I18n.tr("Battery is at %1% - Connect charger immediately!").arg(batteryLevel), true, "battery-critical");
}
return;
}
if (batteryLevel > SettingsData.batteryCriticalThreshold) {
_hasNotifiedCriticalBattery = false;
}
// Low battery check
if (isLowBattery) {
if (!_hasNotifiedLowBattery && SettingsData.batteryNotifyLow) {
_hasNotifiedLowBattery = true;
sendAlert(I18n.tr("Low Battery"), I18n.tr("Battery is at %1%").arg(batteryLevel), true, "battery-low");
sendAlert(I18n.tr("Low Battery"), I18n.tr("Battery is at %1% - Consider charging soon").arg(batteryLevel), true, "battery-low");
}
if (SettingsData.batteryAutoPowerSaver && PowerProfileWatcher.available) {
@@ -146,11 +163,16 @@ Singleton {
}
}
}
if (batteryLevel > SettingsData.batteryLowThreshold) {
_hasNotifiedLowBattery = false;
}
}
onIsChargingChanged: {
if (isCharging) {
_hasNotifiedLowBattery = false;
_hasNotifiedCriticalBattery = false;
} else {
_hasNotifiedChargeLimit = false;
}