PowerProfile: create PowerProfileService, use it for the BarWidget and
PowerProfilesCard
This commit is contained in:
parent
3d51f758f8
commit
144406ae0e
3 changed files with 80 additions and 29 deletions
58
Services/PowerProfileService.qml
Normal file
58
Services/PowerProfileService.qml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.UPower
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property var powerProfiles: PowerProfiles
|
||||
readonly property bool available: powerProfiles && powerProfiles.hasPerformanceProfile
|
||||
property int profile: powerProfiles ? powerProfiles.profile : PowerProfile.Balanced
|
||||
|
||||
function profileName(p) {
|
||||
const prof = (p !== undefined) ? p : profile
|
||||
if (!available)
|
||||
return "Unknown"
|
||||
if (prof === PowerProfile.Performance)
|
||||
return "Performance"
|
||||
if (prof === PowerProfile.Balanced)
|
||||
return "Balanced"
|
||||
if (prof === PowerProfile.PowerSaver)
|
||||
return "Power Saver"
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
function setProfile(p) {
|
||||
if (!available)
|
||||
return
|
||||
try {
|
||||
powerProfiles.profile = p
|
||||
} catch (e) {
|
||||
Logger.error("PowerProfileService", "Failed to set profile:", e)
|
||||
}
|
||||
}
|
||||
|
||||
function cycleProfile() {
|
||||
if (!available)
|
||||
return
|
||||
const current = powerProfiles.profile
|
||||
if (current === PowerProfile.Performance)
|
||||
setProfile(PowerProfile.PowerSaver)
|
||||
else if (current === PowerProfile.Balanced)
|
||||
setProfile(PowerProfile.Performance)
|
||||
else if (current === PowerProfile.PowerSaver)
|
||||
setProfile(PowerProfile.Balanced)
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: powerProfiles
|
||||
function onProfileChanged() {
|
||||
root.profile = powerProfiles.profile
|
||||
ToastService.showNotice("Power Profile", root.profileName())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue