1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

power: support automatic profile switching on battery change (#897)

This commit is contained in:
Marcus Ramberg
2025-12-04 14:37:07 +01:00
committed by GitHub
parent 5b7302b46d
commit 08a97aeff8
4 changed files with 52 additions and 0 deletions

View File

@@ -248,10 +248,12 @@ Singleton {
property int acLockTimeout: 0
property int acSuspendTimeout: 0
property int acSuspendBehavior: SettingsData.SuspendBehavior.Suspend
property string acProfileName: ""
property int batteryMonitorTimeout: 0
property int batteryLockTimeout: 0
property int batterySuspendTimeout: 0
property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend
property string batteryProfileName: ""
property bool lockBeforeSuspend: false
property bool preventIdleForMedia: false
property bool loginctlLockIntegration: true

View File

@@ -147,10 +147,12 @@ var SPEC = {
acLockTimeout: { def: 0 },
acSuspendTimeout: { def: 0 },
acSuspendBehavior: { def: 0 },
acProfileName: { def: "" },
batteryMonitorTimeout: { def: 0 },
batteryLockTimeout: { def: 0 },
batterySuspendTimeout: { def: 0 },
batterySuspendBehavior: { def: 0 },
batteryProfileName: { def: "" },
lockBeforeSuspend: { def: false },
preventIdleForMedia: { def: false },
loginctlLockIntegration: { def: true },

View File

@@ -99,6 +99,43 @@ Item {
SettingsData.set("fadeToLockGracePeriod", periodValues[index]);
}
}
SettingsDropdownRow {
id: powerProfileDropdown
property var profileOptions: [I18n.tr("Don't Change"), Theme.getPowerProfileLabel(0), Theme.getPowerProfileLabel(1), Theme.getPowerProfileLabel(2)]
property var profileValues: ["", "0", "1", "2"]
width: parent.width
addHorizontalPadding: true
text: I18n.tr("Switch to power profile")
options: profileOptions
Connections {
target: powerCategory
function onCurrentIndexChanged() {
const currentProfile = powerCategory.currentIndex === 0 ? SettingsData.acProfileName : SettingsData.batteryProfileName;
const index = powerProfileDropdown.profileValues.indexOf(currentProfile);
powerProfileDropdown.currentValue = powerProfileDropdown.profileOptions[index]
}
}
Component.onCompleted: {
const currentProfile = powerCategory.currentIndex === 0 ? SettingsData.acProfileName : SettingsData.batteryProfileName;
const index = profileValues.indexOf(currentProfile);
currentValue = profileOptions[index]
}
onValueChanged: value => {
const index = profileOptions.indexOf(value);
if (index >= 0) {
const profileValue = profileValues[index];
if (powerCategory.currentIndex === 0) {
SettingsData.set("acProfileName", profileValue);
} else {
SettingsData.set("batteryProfileName", profileValue);
}
}
}
}
Rectangle {
width: parent.width

View File

@@ -72,6 +72,17 @@ Singleton {
}
}
const profileValue = BatteryService.isPluggedIn
? SettingsData.acProfileName
: SettingsData.batteryProfileName;
if (profileValue !== "") {
const targetProfile = parseInt(profileValue);
if (!isNaN(targetProfile) && PowerProfiles.profile !== targetProfile) {
PowerProfiles.profile = targetProfile;
}
}
previousPluggedState = isPluggedIn;
}