mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 08:22:51 -05:00
upower: more sensible usage of upower
This commit is contained in:
@@ -4,7 +4,7 @@ import QtQuick
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
||||||
QtObject {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
// Reference to the main shell root for calling functions
|
// Reference to the main shell root for calling functions
|
||||||
@@ -548,4 +548,65 @@ QtObject {
|
|||||||
property string iconFontFilled: "Material Symbols Rounded"
|
property string iconFontFilled: "Material Symbols Rounded"
|
||||||
property int iconFontWeight: Font.Normal
|
property int iconFontWeight: Font.Normal
|
||||||
property int iconFontFilledWeight: Font.Medium
|
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 QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
import Quickshell.Io
|
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property bool batteryAvailable: UPower.displayDevice?.isLaptopBattery ?? false
|
readonly property var device: UPower.displayDevice
|
||||||
property int batteryLevel: batteryAvailable ? Math.round(UPower.displayDevice.percentage * 100) : 0
|
readonly property bool batteryAvailable: device && device.ready && device.isLaptopBattery
|
||||||
property string batteryStatus: {
|
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 (!batteryAvailable) return "No Battery"
|
||||||
if (UPower.displayDevice.state === UPowerDeviceState.Charging) return "Charging"
|
return UPowerDeviceState.toString(device.state)
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
property int timeRemaining: {
|
|
||||||
|
readonly property int timeRemaining: {
|
||||||
if (!batteryAvailable) return 0
|
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
|
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery && UPower.onBattery && (typeof PowerProfiles !== "undefined" && PowerProfiles.profile !== PowerProfile.PowerSaver)
|
||||||
property string batteryTechnology: batteryAvailable ? "Li-ion" : "N/A"
|
|
||||||
property int batteryCapacity: batteryAvailable ? Math.round(UPower.displayDevice.energyCapacity * 1000) : 0
|
|
||||||
|
|
||||||
property var powerProfiles: {
|
readonly property var bluetoothDevices: {
|
||||||
if (!powerProfilesAvailable || typeof PowerProfiles === "undefined") {
|
var btDevices = []
|
||||||
return ["power-saver", "balanced", "performance"]
|
for (var i = 0; i < UPower.devices.count; i++) {
|
||||||
}
|
var dev = UPower.devices.get(i)
|
||||||
|
if (dev && dev.ready && (dev.type === UPowerDeviceType.BluetoothGeneric ||
|
||||||
let profiles = [
|
dev.type === UPowerDeviceType.Headphones ||
|
||||||
PowerProfile.PowerSaver,
|
dev.type === UPowerDeviceType.Headset ||
|
||||||
PowerProfile.Balanced,
|
dev.type === UPowerDeviceType.Keyboard ||
|
||||||
PowerProfile.Performance
|
dev.type === UPowerDeviceType.Mouse ||
|
||||||
].filter(profile => {
|
dev.type === UPowerDeviceType.Speakers)) {
|
||||||
if (profile === PowerProfile.Performance && !PowerProfiles.hasPerformanceProfile) {
|
btDevices.push({
|
||||||
return false
|
name: dev.model || UPowerDeviceType.toString(dev.type),
|
||||||
}
|
percentage: Math.round(dev.percentage),
|
||||||
return true
|
type: dev.type
|
||||||
})
|
})
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "balanced"
|
return btDevices
|
||||||
}
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTimeRemaining() {
|
function formatTimeRemaining() {
|
||||||
@@ -214,4 +59,8 @@ Singleton {
|
|||||||
return minutes + "m"
|
return minutes + "m"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBluetoothDevices() {
|
||||||
|
return bluetoothDevices
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import Quickshell.Widgets
|
|||||||
import Quickshell.Wayland
|
import Quickshell.Wayland
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Services
|
import qs.Services
|
||||||
|
import Quickshell.Services.UPower
|
||||||
|
|
||||||
PanelWindow {
|
PanelWindow {
|
||||||
id: batteryControlPopup
|
id: batteryControlPopup
|
||||||
@@ -121,7 +122,7 @@ PanelWindow {
|
|||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 120
|
height: 80
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 0.5)
|
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))
|
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
|
visible: BatteryService.batteryAvailable
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
anchors.fill: parent
|
anchors.left: parent.left
|
||||||
anchors.margins: Theme.spacingL
|
anchors.leftMargin: Theme.spacingL
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
spacing: Theme.spacingL
|
spacing: Theme.spacingL
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: BatteryService.getBatteryIcon()
|
text: Theme.getBatteryIcon(BatteryService.batteryLevel, BatteryService.isCharging, BatteryService.batteryAvailable)
|
||||||
font.family: Theme.iconFont
|
font.family: Theme.iconFont
|
||||||
font.pixelSize: 48
|
font.pixelSize: Theme.iconSizeLarge
|
||||||
color: {
|
color: {
|
||||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||||
if (BatteryService.isCharging) return Theme.primary
|
if (BatteryService.isCharging) return Theme.primary
|
||||||
@@ -146,29 +148,34 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
spacing: Theme.spacingS
|
spacing: 2
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
Text {
|
Row {
|
||||||
text: BatteryService.batteryLevel + "%"
|
spacing: Theme.spacingM
|
||||||
font.pixelSize: Theme.fontSizeXLarge
|
|
||||||
color: {
|
Text {
|
||||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
text: BatteryService.batteryLevel + "%"
|
||||||
if (BatteryService.isCharging) return Theme.primary
|
font.pixelSize: Theme.fontSizeLarge
|
||||||
return Theme.surfaceText
|
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
|
||||||
Text {
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
text: BatteryService.batteryStatus
|
color: {
|
||||||
font.pixelSize: Theme.fontSizeLarge
|
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
||||||
color: {
|
if (BatteryService.isCharging) return Theme.primary
|
||||||
if (BatteryService.isLowBattery && !BatteryService.isCharging) return Theme.error
|
return Theme.surfaceText
|
||||||
if (BatteryService.isCharging) return Theme.primary
|
}
|
||||||
return Theme.surfaceText
|
font.weight: Font.Medium
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
font.weight: Font.Medium
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
@@ -179,7 +186,7 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||||
visible: text.length > 0
|
visible: text.length > 0
|
||||||
}
|
}
|
||||||
@@ -202,7 +209,7 @@ PanelWindow {
|
|||||||
spacing: Theme.spacingL
|
spacing: Theme.spacingL
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: BatteryService.getBatteryIcon()
|
text: Theme.getBatteryIcon(0, false, false)
|
||||||
font.family: Theme.iconFont
|
font.family: Theme.iconFont
|
||||||
font.pixelSize: 36
|
font.pixelSize: 36
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
@@ -242,34 +249,14 @@ PanelWindow {
|
|||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
}
|
}
|
||||||
|
|
||||||
Grid {
|
Row {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
columns: 2
|
spacing: Theme.spacingXL
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Health
|
// Health
|
||||||
Column {
|
Column {
|
||||||
spacing: 2
|
spacing: 2
|
||||||
|
width: (parent.width - Theme.spacingXL) / 2
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "Health"
|
text: "Health"
|
||||||
@@ -279,15 +266,20 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: BatteryService.batteryHealth + "%"
|
text: BatteryService.batteryHealth
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
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
|
// Capacity
|
||||||
Column {
|
Column {
|
||||||
spacing: 2
|
spacing: 2
|
||||||
|
width: (parent.width - Theme.spacingXL) / 2
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "Capacity"
|
text: "Capacity"
|
||||||
@@ -297,7 +289,7 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: BatteryService.batteryCapacity > 0 ? BatteryService.batteryCapacity + " mWh" : "Unknown"
|
text: BatteryService.batteryCapacity > 0 ? BatteryService.batteryCapacity.toFixed(1) + " Wh" : "Unknown"
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
}
|
}
|
||||||
@@ -323,15 +315,17 @@ PanelWindow {
|
|||||||
spacing: Theme.spacingS
|
spacing: Theme.spacingS
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: BatteryService.powerProfiles
|
model: (typeof PowerProfiles !== "undefined") ?
|
||||||
|
[PowerProfile.PowerSaver, PowerProfile.Balanced].concat(PowerProfiles.hasPerformanceProfile ? [PowerProfile.Performance] : []) :
|
||||||
|
[PowerProfile.PowerSaver, PowerProfile.Balanced, PowerProfile.Performance]
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 50
|
height: 50
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
color: profileArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) :
|
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))
|
(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: modelData === BatteryService.activePowerProfile ? Theme.primary : "transparent"
|
border.color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : "transparent"
|
||||||
border.width: 2
|
border.width: 2
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
@@ -341,17 +335,10 @@ PanelWindow {
|
|||||||
spacing: Theme.spacingM
|
spacing: Theme.spacingM
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: {
|
text: Theme.getPowerProfileIcon(PowerProfile.toString(modelData))
|
||||||
switch (modelData) {
|
|
||||||
case "power-saver": return "battery_saver"
|
|
||||||
case "balanced": return "battery_std"
|
|
||||||
case "performance": return "flash_on"
|
|
||||||
default: return "settings"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
font.family: Theme.iconFont
|
font.family: Theme.iconFont
|
||||||
font.pixelSize: Theme.iconSize
|
font.pixelSize: Theme.iconSize
|
||||||
color: modelData === BatteryService.activePowerProfile ? Theme.primary : Theme.surfaceText
|
color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : Theme.surfaceText
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,28 +347,14 @@ PanelWindow {
|
|||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: {
|
text: Theme.getPowerProfileLabel(PowerProfile.toString(modelData))
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
font.pixelSize: Theme.fontSizeMedium
|
font.pixelSize: Theme.fontSizeMedium
|
||||||
color: modelData === BatteryService.activePowerProfile ? Theme.primary : Theme.surfaceText
|
color: batteryControlPopup.isActiveProfile(modelData) ? Theme.primary : Theme.surfaceText
|
||||||
font.weight: modelData === BatteryService.activePowerProfile ? Font.Medium : Font.Normal
|
font.weight: batteryControlPopup.isActiveProfile(modelData) ? Font.Medium : Font.Normal
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: {
|
text: Theme.getPowerProfileDescription(PowerProfile.toString(modelData))
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
font.pixelSize: Theme.fontSizeSmall
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||||
}
|
}
|
||||||
@@ -395,13 +368,57 @@ PanelWindow {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
|
||||||
onClicked: {
|
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 {
|
function isActiveProfile(profile) {
|
||||||
target: BatteryService
|
if (typeof PowerProfiles === "undefined") return false
|
||||||
function onShowErrorMessage(message) {
|
return PowerProfiles.profile === profile
|
||||||
|
}
|
||||||
|
|
||||||
|
function setProfile(profile) {
|
||||||
|
if (typeof PowerProfiles === "undefined") {
|
||||||
errorToast.show()
|
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 QtQuick
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Services
|
import qs.Services
|
||||||
|
import Quickshell.Services.UPower
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: batteryWidget
|
id: batteryWidget
|
||||||
@@ -22,7 +23,7 @@ Rectangle {
|
|||||||
spacing: 4
|
spacing: 4
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: BatteryService.getBatteryIcon()
|
text: Theme.getBatteryIcon(BatteryService.batteryLevel, BatteryService.isCharging, BatteryService.batteryAvailable)
|
||||||
font.family: Theme.iconFont
|
font.family: Theme.iconFont
|
||||||
font.pixelSize: Theme.iconSize - 6
|
font.pixelSize: Theme.iconSize - 6
|
||||||
color: {
|
color: {
|
||||||
@@ -99,12 +100,11 @@ Rectangle {
|
|||||||
id: tooltipText
|
id: tooltipText
|
||||||
text: {
|
text: {
|
||||||
if (!BatteryService.batteryAvailable) {
|
if (!BatteryService.batteryAvailable) {
|
||||||
let profile = BatteryService.activePowerProfile
|
if (typeof PowerProfiles === "undefined") return "Power Management"
|
||||||
switch(profile) {
|
switch(PowerProfiles.profile) {
|
||||||
case "power-saver": return "Power Profile: Power Saver"
|
case PowerProfile.PowerSaver: return "Power Profile: Power Saver"
|
||||||
case "balanced": return "Power Profile: Balanced"
|
case PowerProfile.Performance: return "Power Profile: Performance"
|
||||||
case "performance": return "Power Profile: Performance"
|
default: return "Power Profile: Balanced"
|
||||||
default: return "Power Profile: " + profile
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user