mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-06-11 00:47:22 +00:00
Expose power profiles in battery tile
Use the existing power profile control in the battery quick setting so users can see and cycle available profiles without opening settings.
This commit is contained in:
parent
0ec1794929
commit
85b5aec742
1 changed files with 49 additions and 3 deletions
|
|
@ -5,11 +5,57 @@ import QtQuick 2.15
|
||||||
|
|
||||||
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
|
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
|
||||||
import org.kde.plasma.private.mobileshell as MobileShell
|
import org.kde.plasma.private.mobileshell as MobileShell
|
||||||
|
import org.kde.plasma.private.mobileshell.gamingshellplugin as GamingShell
|
||||||
|
|
||||||
QS.QuickSetting {
|
QS.QuickSetting {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
readonly property var profileOrder: ["power-saver", "balanced", "performance"]
|
||||||
|
readonly property bool profileAvailable: GamingShell.PowerProfileControl.available
|
||||||
|
&& GamingShell.PowerProfileControl.profiles.length > 0
|
||||||
|
property var toggle: profileAvailable ? root.cycleProfile : undefined
|
||||||
|
|
||||||
text: i18n("Battery")
|
text: i18n("Battery")
|
||||||
status: i18n("%1%", MobileShell.BatteryInfo.percent)
|
status: profileAvailable
|
||||||
icon: "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "")
|
? i18n("%1% - %2", MobileShell.BatteryInfo.percent, profileLabel(GamingShell.PowerProfileControl.activeProfile))
|
||||||
enabled: false
|
: i18n("%1%", MobileShell.BatteryInfo.percent)
|
||||||
|
icon: profileAvailable ? profileIcon(GamingShell.PowerProfileControl.activeProfile)
|
||||||
|
: "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "")
|
||||||
|
enabled: profileAvailable && GamingShell.PowerProfileControl.activeProfile !== "balanced"
|
||||||
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
settingsCommand: "plasma-open-settings kcm_mobile_power"
|
||||||
|
|
||||||
|
function profileLabel(profile) {
|
||||||
|
switch (profile) {
|
||||||
|
case "performance": return i18n("Performance")
|
||||||
|
case "balanced": return i18n("Balanced")
|
||||||
|
case "power-saver": return i18n("Power Saver")
|
||||||
|
default: return profile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function profileIcon(profile) {
|
||||||
|
switch (profile) {
|
||||||
|
case "performance": return "speedometer"
|
||||||
|
case "power-saver": return "battery-profile-powersave"
|
||||||
|
default: return "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cycleProfile() {
|
||||||
|
let availableProfiles = []
|
||||||
|
for (let i = 0; i < profileOrder.length; ++i) {
|
||||||
|
let profile = profileOrder[i]
|
||||||
|
if (GamingShell.PowerProfileControl.profiles.indexOf(profile) >= 0) {
|
||||||
|
availableProfiles.push(profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (availableProfiles.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentIndex = availableProfiles.indexOf(GamingShell.PowerProfileControl.activeProfile)
|
||||||
|
let nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % availableProfiles.length
|
||||||
|
GamingShell.PowerProfileControl.activeProfile = availableProfiles[nextIndex]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue