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:
@@ -248,10 +248,12 @@ Singleton {
|
|||||||
property int acLockTimeout: 0
|
property int acLockTimeout: 0
|
||||||
property int acSuspendTimeout: 0
|
property int acSuspendTimeout: 0
|
||||||
property int acSuspendBehavior: SettingsData.SuspendBehavior.Suspend
|
property int acSuspendBehavior: SettingsData.SuspendBehavior.Suspend
|
||||||
|
property string acProfileName: ""
|
||||||
property int batteryMonitorTimeout: 0
|
property int batteryMonitorTimeout: 0
|
||||||
property int batteryLockTimeout: 0
|
property int batteryLockTimeout: 0
|
||||||
property int batterySuspendTimeout: 0
|
property int batterySuspendTimeout: 0
|
||||||
property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend
|
property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend
|
||||||
|
property string batteryProfileName: ""
|
||||||
property bool lockBeforeSuspend: false
|
property bool lockBeforeSuspend: false
|
||||||
property bool preventIdleForMedia: false
|
property bool preventIdleForMedia: false
|
||||||
property bool loginctlLockIntegration: true
|
property bool loginctlLockIntegration: true
|
||||||
|
|||||||
@@ -147,10 +147,12 @@ var SPEC = {
|
|||||||
acLockTimeout: { def: 0 },
|
acLockTimeout: { def: 0 },
|
||||||
acSuspendTimeout: { def: 0 },
|
acSuspendTimeout: { def: 0 },
|
||||||
acSuspendBehavior: { def: 0 },
|
acSuspendBehavior: { def: 0 },
|
||||||
|
acProfileName: { def: "" },
|
||||||
batteryMonitorTimeout: { def: 0 },
|
batteryMonitorTimeout: { def: 0 },
|
||||||
batteryLockTimeout: { def: 0 },
|
batteryLockTimeout: { def: 0 },
|
||||||
batterySuspendTimeout: { def: 0 },
|
batterySuspendTimeout: { def: 0 },
|
||||||
batterySuspendBehavior: { def: 0 },
|
batterySuspendBehavior: { def: 0 },
|
||||||
|
batteryProfileName: { def: "" },
|
||||||
lockBeforeSuspend: { def: false },
|
lockBeforeSuspend: { def: false },
|
||||||
preventIdleForMedia: { def: false },
|
preventIdleForMedia: { def: false },
|
||||||
loginctlLockIntegration: { def: true },
|
loginctlLockIntegration: { def: true },
|
||||||
|
|||||||
@@ -99,6 +99,43 @@ Item {
|
|||||||
SettingsData.set("fadeToLockGracePeriod", periodValues[index]);
|
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 {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|||||||
@@ -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;
|
previousPluggedState = isPluggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user