mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 13:32:50 -05:00
upower: more sensible usage of upower
This commit is contained in:
@@ -4,7 +4,7 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
// Reference to the main shell root for calling functions
|
||||
@@ -548,4 +548,65 @@ QtObject {
|
||||
property string iconFontFilled: "Material Symbols Rounded"
|
||||
property int iconFontWeight: Font.Normal
|
||||
property int iconFontFilledWeight: Font.Medium
|
||||
|
||||
function getBatteryIcon(level, isCharging, batteryAvailable) {
|
||||
if (!batteryAvailable) {
|
||||
return _getBatteryPowerProfileIcon()
|
||||
}
|
||||
|
||||
if (isCharging) {
|
||||
if (level >= 90) return "battery_charging_full"
|
||||
if (level >= 80) return "battery_charging_90"
|
||||
if (level >= 60) return "battery_charging_80"
|
||||
if (level >= 50) return "battery_charging_60"
|
||||
if (level >= 30) return "battery_charging_50"
|
||||
if (level >= 20) return "battery_charging_30"
|
||||
return "battery_charging_20"
|
||||
} else {
|
||||
if (level >= 95) return "battery_full"
|
||||
if (level >= 85) return "battery_6_bar"
|
||||
if (level >= 70) return "battery_5_bar"
|
||||
if (level >= 55) return "battery_4_bar"
|
||||
if (level >= 40) return "battery_3_bar"
|
||||
if (level >= 25) return "battery_2_bar"
|
||||
if (level >= 10) return "battery_1_bar"
|
||||
return "battery_alert"
|
||||
}
|
||||
}
|
||||
|
||||
function _getBatteryPowerProfileIcon() {
|
||||
if (typeof PowerProfiles === "undefined") return "balance"
|
||||
switch(PowerProfiles.profile) {
|
||||
case PowerProfile.PowerSaver: return "energy_savings_leaf"
|
||||
case PowerProfile.Performance: return "rocket_launch"
|
||||
default: return "balance"
|
||||
}
|
||||
}
|
||||
|
||||
function getPowerProfileIcon(profile) {
|
||||
switch (profile) {
|
||||
case "power-saver": return "battery_saver"
|
||||
case "balanced": return "battery_std"
|
||||
case "performance": return "flash_on"
|
||||
default: return "settings"
|
||||
}
|
||||
}
|
||||
|
||||
function getPowerProfileLabel(profile) {
|
||||
switch (profile) {
|
||||
case "power-saver": return "Power Saver"
|
||||
case "balanced": return "Balanced"
|
||||
case "performance": return "Performance"
|
||||
default: return profile.charAt(0).toUpperCase() + profile.slice(1)
|
||||
}
|
||||
}
|
||||
|
||||
function getPowerProfileDescription(profile) {
|
||||
switch (profile) {
|
||||
case "power-saver": return "Extend battery life"
|
||||
case "balanced": return "Balance power and performance"
|
||||
case "performance": return "Prioritize performance"
|
||||
default: return "Custom power profile"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,203 +3,48 @@ pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.UPower
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property bool batteryAvailable: UPower.displayDevice?.isLaptopBattery ?? false
|
||||
property int batteryLevel: batteryAvailable ? Math.round(UPower.displayDevice.percentage * 100) : 0
|
||||
property string batteryStatus: {
|
||||
readonly property var device: UPower.displayDevice
|
||||
readonly property bool batteryAvailable: device && device.ready && device.isLaptopBattery
|
||||
readonly property int batteryLevel: batteryAvailable ? device.percentage * 100.0 : 0
|
||||
readonly property bool isCharging: batteryAvailable && device.state === UPowerDeviceState.Charging
|
||||
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= 20
|
||||
readonly property string batteryHealth: batteryAvailable && device.healthSupported ? Math.round(device.healthPercentage * 100.0) + "%" : "N/A"
|
||||
readonly property real batteryCapacity: batteryAvailable && device.energyCapacity > 0 ? device.energyCapacity : 0
|
||||
|
||||
readonly property string batteryStatus: {
|
||||
if (!batteryAvailable) return "No Battery"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.Charging) return "Charging"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.Discharging) return "Discharging"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.FullyCharged) return "Full"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.Empty) return "Empty"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.PendingCharge) return "Pending Charge"
|
||||
if (UPower.displayDevice.state === UPowerDeviceState.PendingDischarge) return "Pending Discharge"
|
||||
return "Unknown"
|
||||
return UPowerDeviceState.toString(device.state)
|
||||
}
|
||||
property int timeRemaining: {
|
||||
|
||||
readonly property int timeRemaining: {
|
||||
if (!batteryAvailable) return 0
|
||||
return UPower.onBattery ? (UPower.displayDevice.timeToEmpty || 0) : (UPower.displayDevice.timeToFull || 0)
|
||||
return isCharging ? (device.timeToFull || 0) : (device.timeToEmpty || 0)
|
||||
}
|
||||
property bool isCharging: batteryAvailable && (UPower.displayDevice.state === UPowerDeviceState.Charging || (!UPower.onBattery && batteryLevel < 100))
|
||||
property bool isLowBattery: batteryAvailable && batteryLevel <= 20
|
||||
|
||||
property int batteryHealth: batteryAvailable && UPower.displayDevice.healthSupported ? Math.round(UPower.displayDevice.healthPercentage * 100) : 100
|
||||
property string batteryTechnology: batteryAvailable ? "Li-ion" : "N/A"
|
||||
property int batteryCapacity: batteryAvailable ? Math.round(UPower.displayDevice.energyCapacity * 1000) : 0
|
||||
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery && UPower.onBattery && (typeof PowerProfiles !== "undefined" && PowerProfiles.profile !== PowerProfile.PowerSaver)
|
||||
|
||||
property var powerProfiles: {
|
||||
if (!powerProfilesAvailable || typeof PowerProfiles === "undefined") {
|
||||
return ["power-saver", "balanced", "performance"]
|
||||
}
|
||||
|
||||
let profiles = [
|
||||
PowerProfile.PowerSaver,
|
||||
PowerProfile.Balanced,
|
||||
PowerProfile.Performance
|
||||
].filter(profile => {
|
||||
if (profile === PowerProfile.Performance && !PowerProfiles.hasPerformanceProfile) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return profiles.map(profile => {
|
||||
switch(profile) {
|
||||
case PowerProfile.PowerSaver: return "power-saver"
|
||||
case PowerProfile.Performance: return "performance"
|
||||
case PowerProfile.Balanced:
|
||||
default: return "balanced"
|
||||
}
|
||||
})
|
||||
}
|
||||
property string activePowerProfile: {
|
||||
if (powerProfilesAvailable && typeof PowerProfiles !== "undefined") {
|
||||
try {
|
||||
switch(PowerProfiles.profile) {
|
||||
case PowerProfile.PowerSaver: return "power-saver"
|
||||
case PowerProfile.Performance: return "performance"
|
||||
default: return "balanced"
|
||||
}
|
||||
} catch (error) {
|
||||
return "balanced"
|
||||
readonly property var bluetoothDevices: {
|
||||
var btDevices = []
|
||||
for (var i = 0; i < UPower.devices.count; i++) {
|
||||
var dev = UPower.devices.get(i)
|
||||
if (dev && dev.ready && (dev.type === UPowerDeviceType.BluetoothGeneric ||
|
||||
dev.type === UPowerDeviceType.Headphones ||
|
||||
dev.type === UPowerDeviceType.Headset ||
|
||||
dev.type === UPowerDeviceType.Keyboard ||
|
||||
dev.type === UPowerDeviceType.Mouse ||
|
||||
dev.type === UPowerDeviceType.Speakers)) {
|
||||
btDevices.push({
|
||||
name: dev.model || UPowerDeviceType.toString(dev.type),
|
||||
percentage: Math.round(dev.percentage),
|
||||
type: dev.type
|
||||
})
|
||||
}
|
||||
}
|
||||
return "balanced"
|
||||
}
|
||||
property bool powerProfilesAvailable: false
|
||||
property string powerProfilesError: powerProfilesAvailable ? "" : "Power profiles daemon not available. Install and enable power-profiles-daemon."
|
||||
property bool suggestPowerSaver: batteryAvailable && isLowBattery && UPower.onBattery && activePowerProfile !== "power-saver"
|
||||
|
||||
Process {
|
||||
id: checkPowerProfilesDaemon
|
||||
command: ["bash", "-c", "systemctl is-active power-profiles-daemon || pgrep -x power-profiles-daemon > /dev/null"]
|
||||
running: false
|
||||
|
||||
onExited: (exitCode) => {
|
||||
powerProfilesAvailable = (exitCode === 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Connections {
|
||||
target: UPower
|
||||
function onOnBatteryChanged() {
|
||||
batteryAvailableChanged()
|
||||
isChargingChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: typeof PowerProfiles !== "undefined" ? PowerProfiles : null
|
||||
function onProfileChanged() {
|
||||
activePowerProfileChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: UPower.displayDevice
|
||||
function onPercentageChanged() {
|
||||
batteryLevelChanged()
|
||||
isLowBatteryChanged()
|
||||
}
|
||||
function onStateChanged() {
|
||||
batteryStatusChanged()
|
||||
isChargingChanged()
|
||||
}
|
||||
function onTimeToEmptyChanged() {
|
||||
timeRemainingChanged()
|
||||
}
|
||||
function onTimeToFullChanged() {
|
||||
timeRemainingChanged()
|
||||
}
|
||||
function onReadyChanged() {
|
||||
batteryAvailableChanged()
|
||||
}
|
||||
function onIsLaptopBatteryChanged() {
|
||||
batteryAvailableChanged()
|
||||
}
|
||||
function onEnergyChanged() {
|
||||
batteryCapacityChanged()
|
||||
}
|
||||
function onEnergyCapacityChanged() {
|
||||
batteryCapacityChanged()
|
||||
}
|
||||
function onHealthPercentageChanged() {
|
||||
batteryHealthChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
checkPowerProfilesDaemon.running = true
|
||||
}
|
||||
|
||||
signal showErrorMessage(string message)
|
||||
|
||||
function setBatteryProfile(profileName) {
|
||||
console.log("Setting power profile to:", profileName)
|
||||
|
||||
if (!powerProfilesAvailable) {
|
||||
console.warn("Power profiles daemon not available")
|
||||
showErrorMessage("power-profiles-daemon not available")
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
switch(profileName) {
|
||||
case "power-saver":
|
||||
PowerProfiles.profile = PowerProfile.PowerSaver
|
||||
break
|
||||
case "balanced":
|
||||
PowerProfiles.profile = PowerProfile.Balanced
|
||||
break
|
||||
case "performance":
|
||||
PowerProfiles.profile = PowerProfile.Performance
|
||||
break
|
||||
default:
|
||||
console.warn("Unknown profile:", profileName)
|
||||
return
|
||||
}
|
||||
console.log("Power profile set successfully to:", PowerProfiles.profile)
|
||||
} catch (error) {
|
||||
console.error("Failed to set power profile:", error)
|
||||
showErrorMessage("power-profiles-daemon not available")
|
||||
}
|
||||
}
|
||||
|
||||
function getBatteryIcon() {
|
||||
if (!batteryAvailable) {
|
||||
switch(activePowerProfile) {
|
||||
case "power-saver": return "energy_savings_leaf"
|
||||
case "performance": return "rocket_launch"
|
||||
default: return "balance"
|
||||
}
|
||||
}
|
||||
|
||||
const level = batteryLevel
|
||||
const charging = isCharging
|
||||
|
||||
if (charging) {
|
||||
if (level >= 90) return "battery_charging_full"
|
||||
if (level >= 80) return "battery_charging_90"
|
||||
if (level >= 60) return "battery_charging_80"
|
||||
if (level >= 50) return "battery_charging_60"
|
||||
if (level >= 30) return "battery_charging_50"
|
||||
if (level >= 20) return "battery_charging_30"
|
||||
return "battery_charging_20"
|
||||
} else {
|
||||
if (level >= 95) return "battery_full"
|
||||
if (level >= 85) return "battery_6_bar"
|
||||
if (level >= 70) return "battery_5_bar"
|
||||
if (level >= 55) return "battery_4_bar"
|
||||
if (level >= 40) return "battery_3_bar"
|
||||
if (level >= 25) return "battery_2_bar"
|
||||
if (level >= 10) return "battery_1_bar"
|
||||
return "battery_alert"
|
||||
}
|
||||
return btDevices
|
||||
}
|
||||
|
||||
function formatTimeRemaining() {
|
||||
@@ -214,4 +59,8 @@ Singleton {
|
||||
return minutes + "m"
|
||||
}
|
||||
}
|
||||
|
||||
function getBluetoothDevices() {
|
||||
return bluetoothDevices
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import Quickshell.Widgets
|
||||
import Quickshell.Wayland
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import Quickshell.Services.UPower
|
||||
|
||||
PanelWindow {
|
||||
id: batteryControlPopup
|
||||
@@ -121,7 +122,7 @@ PanelWindow {
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 120
|
||||
height: 80
|
||||
radius: Theme.cornerRadius
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 0.5)
|
||||
border.color: BatteryService.isCharging ? Theme.primary : (BatteryService.isLowBattery ? Theme.error : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12))
|
||||
@@ -129,14 +130,15 @@ PanelWindow {
|
||||
visible: BatteryService.batteryAvailable
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingL
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingL
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingL
|
||||
|
||||
Text {
|
||||
text: BatteryService.getBatteryIcon()
|
||||
text: Theme.getBatteryIcon(BatteryService.batteryLevel, BatteryService.isCharging, BatteryService.batteryAvailable)
|
||||
font.family: Theme.iconFont
|
||||
font.pixelSize: 48
|
||||
font.pixelSize: Theme.iconSizeLarge
|
||||
color: {
|
||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||
if (BatteryService.isCharging) return Theme.primary
|
||||
@@ -146,29 +148,34 @@ PanelWindow {
|
||||
}
|
||||
|
||||
Column {
|
||||
spacing: Theme.spacingS
|
||||
spacing: 2
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryLevel + "%"
|
||||
font.pixelSize: Theme.fontSizeXLarge
|
||||
color: {
|
||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||
if (BatteryService.isCharging) return Theme.primary
|
||||
return Theme.surfaceText
|
||||
Row {
|
||||
spacing: Theme.spacingM
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryLevel + "%"
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: {
|
||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||
if (BatteryService.isCharging) return Theme.primary
|
||||
return Theme.surfaceText
|
||||
}
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryStatus
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: {
|
||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||
if (BatteryService.isCharging) return Theme.primary
|
||||
return Theme.surfaceText
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryStatus
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: {
|
||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||
if (BatteryService.isCharging) return Theme.primary
|
||||
return Theme.surfaceText
|
||||
}
|
||||
font.weight: Font.Medium
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
|
||||
Text {
|
||||
@@ -179,7 +186,7 @@ PanelWindow {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||
visible: text.length > 0
|
||||
}
|
||||
@@ -202,7 +209,7 @@ PanelWindow {
|
||||
spacing: Theme.spacingL
|
||||
|
||||
Text {
|
||||
text: BatteryService.getBatteryIcon()
|
||||
text: Theme.getBatteryIcon(0, false, false)
|
||||
font.family: Theme.iconFont
|
||||
font.pixelSize: 36
|
||||
color: Theme.surfaceText
|
||||
@@ -242,34 +249,14 @@ PanelWindow {
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
|
||||
Grid {
|
||||
Row {
|
||||
width: parent.width
|
||||
columns: 2
|
||||
columnSpacing: Theme.spacingL
|
||||
rowSpacing: Theme.spacingM
|
||||
|
||||
// Technology
|
||||
Column {
|
||||
spacing: 2
|
||||
|
||||
Text {
|
||||
text: "Technology"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryTechnology
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
}
|
||||
|
||||
spacing: Theme.spacingXL
|
||||
|
||||
// Health
|
||||
Column {
|
||||
spacing: 2
|
||||
width: (parent.width - Theme.spacingXL) / 2
|
||||
|
||||
Text {
|
||||
text: "Health"
|
||||
@@ -279,15 +266,20 @@ PanelWindow {
|
||||
}
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryHealth + "%"
|
||||
text: BatteryService.batteryHealth
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: BatteryService.batteryHealth < 80 ? Theme.error : Theme.surfaceText
|
||||
color: {
|
||||
if (BatteryService.batteryHealth === "N/A") return Theme.surfaceText
|
||||
var healthNum = parseInt(BatteryService.batteryHealth)
|
||||
return healthNum < 80 ? Theme.error : Theme.surfaceText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Capacity
|
||||
Column {
|
||||
spacing: 2
|
||||
width: (parent.width - Theme.spacingXL) / 2
|
||||
|
||||
Text {
|
||||
text: "Capacity"
|
||||
@@ -297,7 +289,7 @@ PanelWindow {
|
||||
}
|
||||
|
||||
Text {
|
||||
text: BatteryService.batteryCapacity > 0 ? BatteryService.batteryCapacity + " mWh" : "Unknown"
|
||||
text: BatteryService.batteryCapacity > 0 ? BatteryService.batteryCapacity.toFixed(1) + " Wh" : "Unknown"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
@@ -323,15 +315,17 @@ PanelWindow {
|
||||
spacing: Theme.spacingS
|
||||
|
||||
Repeater {
|
||||
model: BatteryService.powerProfiles
|
||||
model: (typeof PowerProfiles !== "undefined") ?
|
||||
[PowerProfile.PowerSaver, PowerProfile.Balanced].concat(PowerProfiles.hasPerformanceProfile ? [PowerProfile.Performance] : []) :
|
||||
[PowerProfile.PowerSaver, PowerProfile.Balanced, PowerProfile.Performance]
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 50
|
||||
radius: Theme.cornerRadius
|
||||
color: profileArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) :
|
||||
(modelData === BatteryService.activePowerProfile ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.16) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
border.color: modelData === BatteryService.activePowerProfile ? Theme.primary : "transparent"
|
||||
(batteryControlPopup.isActiveProfile(modelData) ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.16) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
border.color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : "transparent"
|
||||
border.width: 2
|
||||
|
||||
Row {
|
||||
@@ -341,17 +335,10 @@ PanelWindow {
|
||||
spacing: Theme.spacingM
|
||||
|
||||
Text {
|
||||
text: {
|
||||
switch (modelData) {
|
||||
case "power-saver": return "battery_saver"
|
||||
case "balanced": return "battery_std"
|
||||
case "performance": return "flash_on"
|
||||
default: return "settings"
|
||||
}
|
||||
}
|
||||
text: Theme.getPowerProfileIcon(PowerProfile.toString(modelData))
|
||||
font.family: Theme.iconFont
|
||||
font.pixelSize: Theme.iconSize
|
||||
color: modelData === BatteryService.activePowerProfile ? Theme.primary : Theme.surfaceText
|
||||
color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : Theme.surfaceText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
@@ -360,28 +347,14 @@ PanelWindow {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
text: {
|
||||
switch (modelData) {
|
||||
case "power-saver": return "Power Saver"
|
||||
case "balanced": return "Balanced"
|
||||
case "performance": return "Performance"
|
||||
default: return modelData.charAt(0).toUpperCase() + modelData.slice(1)
|
||||
}
|
||||
}
|
||||
text: Theme.getPowerProfileLabel(PowerProfile.toString(modelData))
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: modelData === BatteryService.activePowerProfile ? Theme.primary : Theme.surfaceText
|
||||
font.weight: modelData === BatteryService.activePowerProfile ? Font.Medium : Font.Normal
|
||||
color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : Theme.surfaceText
|
||||
font.weight: batteryControlPopup.isActiveProfile(modelData) ? Font.Medium : Font.Normal
|
||||
}
|
||||
|
||||
Text {
|
||||
text: {
|
||||
switch (modelData) {
|
||||
case "power-saver": return "Extend battery life"
|
||||
case "balanced": return "Balance power and performance"
|
||||
case "performance": return "Prioritize performance"
|
||||
default: return "Custom power profile"
|
||||
}
|
||||
}
|
||||
text: Theme.getPowerProfileDescription(PowerProfile.toString(modelData))
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||
}
|
||||
@@ -395,13 +368,57 @@ PanelWindow {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onClicked: {
|
||||
BatteryService.setBatteryProfile(modelData)
|
||||
batteryControlPopup.setProfile(modelData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Degradation reason warning
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 60
|
||||
radius: Theme.cornerRadius
|
||||
color: Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.12)
|
||||
border.color: Theme.error
|
||||
border.width: 2
|
||||
visible: (typeof PowerProfiles !== "undefined") && PowerProfiles.degradationReason !== PerformanceDegradationReason.None
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingL
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingM
|
||||
|
||||
Text {
|
||||
text: "warning"
|
||||
font.family: Theme.iconFont
|
||||
font.pixelSize: Theme.iconSize
|
||||
color: Theme.error
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
spacing: 2
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
text: "Power Profile Degradation"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.error
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
|
||||
Text {
|
||||
text: (typeof PowerProfiles !== "undefined") ? PerformanceDegradationReason.toString(PowerProfiles.degradationReason) : ""
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,10 +456,24 @@ PanelWindow {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: BatteryService
|
||||
function onShowErrorMessage(message) {
|
||||
function isActiveProfile(profile) {
|
||||
if (typeof PowerProfiles === "undefined") return false
|
||||
return PowerProfiles.profile === profile
|
||||
}
|
||||
|
||||
function setProfile(profile) {
|
||||
if (typeof PowerProfiles === "undefined") {
|
||||
errorToast.show()
|
||||
return
|
||||
}
|
||||
|
||||
PowerProfiles.profile = profile
|
||||
|
||||
if (PowerProfiles.profile !== profile) {
|
||||
errorToast.show()
|
||||
} else {
|
||||
console.log("Set power profile to: " + PowerProfile.toString(profile))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import Quickshell.Services.UPower
|
||||
|
||||
Rectangle {
|
||||
id: batteryWidget
|
||||
@@ -22,7 +23,7 @@ Rectangle {
|
||||
spacing: 4
|
||||
|
||||
Text {
|
||||
text: BatteryService.getBatteryIcon()
|
||||
text: Theme.getBatteryIcon(BatteryService.batteryLevel, BatteryService.isCharging, BatteryService.batteryAvailable)
|
||||
font.family: Theme.iconFont
|
||||
font.pixelSize: Theme.iconSize - 6
|
||||
color: {
|
||||
@@ -99,12 +100,11 @@ Rectangle {
|
||||
id: tooltipText
|
||||
text: {
|
||||
if (!BatteryService.batteryAvailable) {
|
||||
let profile = BatteryService.activePowerProfile
|
||||
switch(profile) {
|
||||
case "power-saver": return "Power Profile: Power Saver"
|
||||
case "balanced": return "Power Profile: Balanced"
|
||||
case "performance": return "Power Profile: Performance"
|
||||
default: return "Power Profile: " + profile
|
||||
if (typeof PowerProfiles === "undefined") return "Power Management"
|
||||
switch(PowerProfiles.profile) {
|
||||
case PowerProfile.PowerSaver: return "Power Profile: Power Saver"
|
||||
case PowerProfile.Performance: return "Power Profile: Performance"
|
||||
default: return "Power Profile: Balanced"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user