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

feat: add battery settings tab and update battery widget interactions (#2634)

* feat: add battery settings tab and update battery widget interactions

* fix: import Quickshell.Io in BatteryTab.qml to fix Process type compilation error

* feat: move battery tab under media player and add notify when charge limit reached option

* chore: change default notification settings to false

* feat: move battery tab under Power & Security section in settings

* feat: add notification type button selection for battery alerts
This commit is contained in:
Huỳnh Thiện Lộc
2026-06-18 07:29:23 +07:00
committed by GitHub
parent d5ac0c9aa0
commit 480ffa4ac2
7 changed files with 409 additions and 21 deletions
+53 -1
View File
@@ -102,7 +102,59 @@ Singleton {
// Is the system plugged in (Is not running on battery)
readonly property bool isPluggedIn: !UPower.onBattery
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= 20
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= SettingsData.batteryLowThreshold
property bool _hasNotifiedLowBattery: false
property bool _hasNotifiedChargeLimit: false
function sendAlert(title, message, isWarning, category) {
if (SettingsData.batteryNotificationType === 1) {
Quickshell.execDetached(["notify-send", "-u", isWarning ? "critical" : "normal", "-a", "DMS", "-i", isWarning ? "battery-caution" : "battery-charging", title, message]);
} else {
if (isWarning) {
ToastService.showWarning(title, message, "", category);
} else {
ToastService.showInfo(title, message, "", category);
}
}
}
onBatteryLevelChanged: {
if (isCharging && batteryLevel >= SettingsData.batteryChargeLimit) {
if (!_hasNotifiedChargeLimit && SettingsData.batteryNotifyChargeLimit) {
_hasNotifiedChargeLimit = true;
sendAlert(I18n.tr("Charge Limit Reached"), I18n.tr("Battery has charged to your set limit of %1%").arg(SettingsData.batteryChargeLimit), false, "battery-charge-limit");
}
} else if (!isCharging || batteryLevel < SettingsData.batteryChargeLimit - 2) {
_hasNotifiedChargeLimit = false;
}
if (isCharging || !isLowBattery) {
_hasNotifiedLowBattery = false;
return;
}
if (!isCharging && isLowBattery) {
if (!_hasNotifiedLowBattery && SettingsData.batteryNotifyLow) {
_hasNotifiedLowBattery = true;
sendAlert(I18n.tr("Low Battery"), I18n.tr("Battery is at %1%").arg(batteryLevel), true, "battery-low");
}
if (SettingsData.batteryAutoPowerSaver && PowerProfileWatcher.available) {
if (PowerProfileWatcher.currentProfile !== PowerProfile.PowerSaver) {
PowerProfileWatcher.applyProfile(PowerProfile.PowerSaver);
}
}
}
}
onIsChargingChanged: {
if (isCharging) {
_hasNotifiedLowBattery = false;
} else {
_hasNotifiedChargeLimit = false;
}
}
onIsPluggedInChanged: {
if (suppressSound || !batteryAvailable) {