PowerProfile: create PowerProfileService, use it for the BarWidget and

PowerProfilesCard
This commit is contained in:
Ly-sec 2025-09-09 17:12:56 +02:00
parent 3d51f758f8
commit 144406ae0e
3 changed files with 80 additions and 29 deletions

View file

@ -11,8 +11,7 @@ NIconButton {
property ShellScreen screen
property real scaling: 1.0
property var powerProfiles: PowerProfiles
readonly property bool hasPP: powerProfiles.hasPerformanceProfile
readonly property bool hasPP: PowerProfileService.available
sizeRatio: 0.8
visible: hasPP
@ -20,34 +19,29 @@ NIconButton {
function profileIcon() {
if (!hasPP)
return "yin-yang"
if (powerProfiles.profile === PowerProfile.Performance)
if (PowerProfileService.profile === PowerProfile.Performance)
return "speedometer2"
if (powerProfiles.profile === PowerProfile.Balanced)
if (PowerProfileService.profile === PowerProfile.Balanced)
return "yin-yang"
if (powerProfiles.profile === PowerProfile.PowerSaver)
if (PowerProfileService.profile === PowerProfile.PowerSaver)
return "leaf"
}
function profileName() {
if (!hasPP)
return "Unknown"
if (powerProfiles.profile === PowerProfile.Performance)
if (PowerProfileService.profile === PowerProfile.Performance)
return "Performance"
if (powerProfiles.profile === PowerProfile.Balanced)
if (PowerProfileService.profile === PowerProfile.Balanced)
return "Balanced"
if (powerProfiles.profile === PowerProfile.PowerSaver)
if (PowerProfileService.profile === PowerProfile.PowerSaver)
return "Power Saver"
}
function changeProfile() {
if (!hasPP)
return
if (powerProfiles.profile === PowerProfile.Performance)
powerProfiles.profile = PowerProfile.PowerSaver
else if (powerProfiles.profile === PowerProfile.Balanced)
powerProfiles.profile = PowerProfile.Performance
else if (powerProfiles.profile === PowerProfile.PowerSaver)
powerProfiles.profile = PowerProfile.Balanced
PowerProfileService.cycleProfile()
}
icon: root.profileIcon()

View file

@ -13,9 +13,8 @@ NBox {
Layout.preferredWidth: 1
implicitHeight: powerRow.implicitHeight + Style.marginM * 2 * scaling
// PowerProfiles service
property var powerProfiles: PowerProfiles
readonly property bool hasPP: powerProfiles.hasPerformanceProfile
// Centralized service
readonly property bool hasPP: PowerProfileService.available
property real spacing: 0
RowLayout {
@ -32,12 +31,12 @@ NBox {
tooltipText: "Set performance power profile."
enabled: hasPP
opacity: enabled ? Style.opacityFull : Style.opacityMedium
colorBg: (enabled && powerProfiles.profile === PowerProfile.Performance) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && powerProfiles.profile === PowerProfile.Performance) ? Color.mOnPrimary : Color.mPrimary
colorBg: (enabled
&& PowerProfileService.profile === PowerProfile.Performance) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && PowerProfileService.profile === PowerProfile.Performance) ? Color.mOnPrimary : Color.mPrimary
onClicked: {
if (enabled) {
powerProfiles.profile = PowerProfile.Performance
ToastService.showNotice("Power Profile", "Performance")
PowerProfileService.setProfile(PowerProfile.Performance)
}
}
}
@ -47,12 +46,12 @@ NBox {
tooltipText: "Set balanced power profile."
enabled: hasPP
opacity: enabled ? Style.opacityFull : Style.opacityMedium
colorBg: (enabled && powerProfiles.profile === PowerProfile.Balanced) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && powerProfiles.profile === PowerProfile.Balanced) ? Color.mOnPrimary : Color.mPrimary
colorBg: (enabled
&& PowerProfileService.profile === PowerProfile.Balanced) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && PowerProfileService.profile === PowerProfile.Balanced) ? Color.mOnPrimary : Color.mPrimary
onClicked: {
if (enabled) {
powerProfiles.profile = PowerProfile.Balanced
ToastService.showNotice("Power Profile", "Balanced")
PowerProfileService.setProfile(PowerProfile.Balanced)
}
}
}
@ -62,12 +61,12 @@ NBox {
tooltipText: "Set eco power profile."
enabled: hasPP
opacity: enabled ? Style.opacityFull : Style.opacityMedium
colorBg: (enabled && powerProfiles.profile === PowerProfile.PowerSaver) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && powerProfiles.profile === PowerProfile.PowerSaver) ? Color.mOnPrimary : Color.mPrimary
colorBg: (enabled
&& PowerProfileService.profile === PowerProfile.PowerSaver) ? Color.mPrimary : Color.mSurfaceVariant
colorFg: (enabled && PowerProfileService.profile === PowerProfile.PowerSaver) ? Color.mOnPrimary : Color.mPrimary
onClicked: {
if (enabled) {
powerProfiles.profile = PowerProfile.PowerSaver
ToastService.showNotice("Power Profile", "Power Saver")
PowerProfileService.setProfile(PowerProfile.PowerSaver)
}
}
}