mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
PowerProfile: Standardization + Factorisation. Fix #307
This commit is contained in:
@@ -11,45 +11,16 @@ NIconButton {
|
||||
|
||||
property ShellScreen screen
|
||||
property real scaling: 1.0
|
||||
readonly property bool hasPP: PowerProfileService.available
|
||||
|
||||
baseSize: Style.capsuleHeight
|
||||
visible: hasPP
|
||||
visible: PowerProfileService.available
|
||||
|
||||
function profileIcon() {
|
||||
if (!hasPP)
|
||||
return "balanced"
|
||||
if (PowerProfileService.profile === PowerProfile.Performance)
|
||||
return "performance"
|
||||
if (PowerProfileService.profile === PowerProfile.Balanced)
|
||||
return "balanced"
|
||||
if (PowerProfileService.profile === PowerProfile.PowerSaver)
|
||||
return "powersaver"
|
||||
}
|
||||
|
||||
function profileName() {
|
||||
if (!hasPP)
|
||||
return "Unknown"
|
||||
if (PowerProfileService.profile === PowerProfile.Performance)
|
||||
return "Performance"
|
||||
if (PowerProfileService.profile === PowerProfile.Balanced)
|
||||
return "Balanced"
|
||||
if (PowerProfileService.profile === PowerProfile.PowerSaver)
|
||||
return "Power Saver"
|
||||
}
|
||||
|
||||
function changeProfile() {
|
||||
if (!hasPP)
|
||||
return
|
||||
PowerProfileService.cycleProfile()
|
||||
}
|
||||
|
||||
icon: root.profileIcon()
|
||||
tooltipText: root.profileName()
|
||||
icon: PowerProfileService.getIcon()
|
||||
tooltipText: `Current power profile is "${PowerProfileService.getName()}".`
|
||||
compact: (Settings.data.bar.density === "compact")
|
||||
colorBg: (PowerProfileService.profile === PowerProfile.Balanced) ? (Settings.data.bar.showCapsule ? Color.mSurfaceVariant : Color.transparent) : Color.mPrimary
|
||||
colorFg: (PowerProfileService.profile === PowerProfile.Balanced) ? Color.mOnSurface : Color.mOnPrimary
|
||||
colorBorder: Color.transparent
|
||||
colorBorderHover: Color.transparent
|
||||
onClicked: root.changeProfile()
|
||||
onClicked: PowerProfileService.cycleProfile()
|
||||
}
|
||||
|
||||
@@ -25,45 +25,33 @@ NBox {
|
||||
}
|
||||
// Performance
|
||||
NIconButton {
|
||||
icon: "performance"
|
||||
tooltipText: "Set performance power profile."
|
||||
icon: PowerProfileService.getIcon(PowerProfile.Performance)
|
||||
tooltipText: `Set "${PowerProfileService.getName(PowerProfile.Performance)}" power profile.`
|
||||
enabled: hasPP
|
||||
opacity: enabled ? Style.opacityFull : Style.opacityMedium
|
||||
colorBg: (enabled && PowerProfileService.profile === PowerProfile.Performance) ? Color.mPrimary : Color.mSurfaceVariant
|
||||
colorFg: (enabled && PowerProfileService.profile === PowerProfile.Performance) ? Color.mOnPrimary : Color.mPrimary
|
||||
onClicked: {
|
||||
if (enabled) {
|
||||
PowerProfileService.setProfile(PowerProfile.Performance)
|
||||
}
|
||||
}
|
||||
onClicked: PowerProfileService.setProfile(PowerProfile.Performance)
|
||||
}
|
||||
// Balanced
|
||||
NIconButton {
|
||||
icon: "balanced"
|
||||
tooltipText: "Set balanced power profile."
|
||||
icon: PowerProfileService.getIcon(PowerProfile.Balanced)
|
||||
tooltipText: `Set "${PowerProfileService.getName(PowerProfile.Balanced)}" power profile.`
|
||||
enabled: hasPP
|
||||
opacity: enabled ? Style.opacityFull : Style.opacityMedium
|
||||
colorBg: (enabled && PowerProfileService.profile === PowerProfile.Balanced) ? Color.mPrimary : Color.mSurfaceVariant
|
||||
colorFg: (enabled && PowerProfileService.profile === PowerProfile.Balanced) ? Color.mOnPrimary : Color.mPrimary
|
||||
onClicked: {
|
||||
if (enabled) {
|
||||
PowerProfileService.setProfile(PowerProfile.Balanced)
|
||||
}
|
||||
}
|
||||
onClicked: PowerProfileService.setProfile(PowerProfile.Balanced)
|
||||
}
|
||||
// Eco
|
||||
NIconButton {
|
||||
icon: "powersaver"
|
||||
tooltipText: "Set eco power profile."
|
||||
icon: PowerProfileService.getIcon(PowerProfile.PowerSaver)
|
||||
tooltipText: `Set "${PowerProfileService.getName(PowerProfile.PowerSaver)}" power profile.`
|
||||
enabled: hasPP
|
||||
opacity: enabled ? Style.opacityFull : Style.opacityMedium
|
||||
colorBg: (enabled && PowerProfileService.profile === PowerProfile.PowerSaver) ? Color.mPrimary : Color.mSurfaceVariant
|
||||
colorFg: (enabled && PowerProfileService.profile === PowerProfile.PowerSaver) ? Color.mOnPrimary : Color.mPrimary
|
||||
onClicked: {
|
||||
if (enabled) {
|
||||
PowerProfileService.setProfile(PowerProfile.PowerSaver)
|
||||
}
|
||||
}
|
||||
onClicked: PowerProfileService.setProfile(PowerProfile.PowerSaver)
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -13,17 +13,40 @@ Singleton {
|
||||
readonly property bool available: powerProfiles && powerProfiles.hasPerformanceProfile
|
||||
property int profile: powerProfiles ? powerProfiles.profile : PowerProfile.Balanced
|
||||
|
||||
function profileName(p) {
|
||||
const prof = (p !== undefined) ? p : profile
|
||||
function getName(p) {
|
||||
if (!available)
|
||||
return "Unknown"
|
||||
if (prof === PowerProfile.Performance)
|
||||
|
||||
const prof = (p !== undefined) ? p : profile
|
||||
|
||||
switch (prof) {
|
||||
case PowerProfile.Performance:
|
||||
return "Performance"
|
||||
if (prof === PowerProfile.Balanced)
|
||||
case PowerProfile.Balanced:
|
||||
return "Balanced"
|
||||
if (prof === PowerProfile.PowerSaver)
|
||||
case PowerProfile.PowerSaver:
|
||||
return "Power Saver"
|
||||
return "Unknown"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
function getIcon(p) {
|
||||
if (!available)
|
||||
return "balanced"
|
||||
|
||||
const prof = (p !== undefined) ? p : profile
|
||||
|
||||
switch (prof) {
|
||||
case PowerProfile.Performance:
|
||||
return "performance"
|
||||
case PowerProfile.Balanced:
|
||||
return "balanced"
|
||||
case PowerProfile.PowerSaver:
|
||||
return "powersaver"
|
||||
default:
|
||||
return "balanced"
|
||||
}
|
||||
}
|
||||
|
||||
function setProfile(p) {
|
||||
@@ -53,9 +76,9 @@ Singleton {
|
||||
function onProfileChanged() {
|
||||
root.profile = powerProfiles.profile
|
||||
// Only show toast if we have a valid profile name (not "Unknown")
|
||||
const profileName = root.profileName()
|
||||
const profileName = root.getName()
|
||||
if (profileName !== "Unknown") {
|
||||
ToastService.showNotice("Power Profile", profileName)
|
||||
ToastService.showNotice("Power Profile Changed", `"${profileName}"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user