mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
battery view improvements
This commit is contained in:
@@ -30,9 +30,58 @@ Rectangle {
|
|||||||
spacing: 4
|
spacing: 4
|
||||||
|
|
||||||
DankIcon {
|
DankIcon {
|
||||||
name: Theme.getBatteryIcon(BatteryService.batteryLevel,
|
name: {
|
||||||
BatteryService.isCharging,
|
if (!BatteryService.batteryAvailable)
|
||||||
BatteryService.batteryAvailable)
|
return "power"
|
||||||
|
|
||||||
|
if (BatteryService.isCharging) {
|
||||||
|
if (BatteryService.batteryLevel >= 90)
|
||||||
|
return "battery_charging_full"
|
||||||
|
if (BatteryService.batteryLevel >= 80)
|
||||||
|
return "battery_charging_90"
|
||||||
|
if (BatteryService.batteryLevel >= 60)
|
||||||
|
return "battery_charging_80"
|
||||||
|
if (BatteryService.batteryLevel >= 50)
|
||||||
|
return "battery_charging_60"
|
||||||
|
if (BatteryService.batteryLevel >= 30)
|
||||||
|
return "battery_charging_50"
|
||||||
|
if (BatteryService.batteryLevel >= 20)
|
||||||
|
return "battery_charging_30"
|
||||||
|
return "battery_charging_20"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if plugged in but not charging (like at 80% charge limit)
|
||||||
|
if (BatteryService.isPluggedIn) {
|
||||||
|
if (BatteryService.batteryLevel >= 90)
|
||||||
|
return "battery_charging_full"
|
||||||
|
if (BatteryService.batteryLevel >= 80)
|
||||||
|
return "battery_charging_90"
|
||||||
|
if (BatteryService.batteryLevel >= 60)
|
||||||
|
return "battery_charging_80"
|
||||||
|
if (BatteryService.batteryLevel >= 50)
|
||||||
|
return "battery_charging_60"
|
||||||
|
if (BatteryService.batteryLevel >= 30)
|
||||||
|
return "battery_charging_50"
|
||||||
|
if (BatteryService.batteryLevel >= 20)
|
||||||
|
return "battery_charging_30"
|
||||||
|
return "battery_charging_20"
|
||||||
|
}
|
||||||
|
|
||||||
|
// On battery power
|
||||||
|
if (BatteryService.batteryLevel >= 95)
|
||||||
|
return "battery_full"
|
||||||
|
if (BatteryService.batteryLevel >= 85)
|
||||||
|
return "battery_6_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 70)
|
||||||
|
return "battery_5_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 55)
|
||||||
|
return "battery_4_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 40)
|
||||||
|
return "battery_3_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 25)
|
||||||
|
return "battery_2_bar"
|
||||||
|
return "battery_1_bar"
|
||||||
|
}
|
||||||
size: Theme.iconSize - 6
|
size: Theme.iconSize - 6
|
||||||
color: {
|
color: {
|
||||||
if (!BatteryService.batteryAvailable)
|
if (!BatteryService.batteryAvailable)
|
||||||
@@ -41,13 +90,12 @@ Rectangle {
|
|||||||
if (BatteryService.isLowBattery && !BatteryService.isCharging)
|
if (BatteryService.isLowBattery && !BatteryService.isCharging)
|
||||||
return Theme.error
|
return Theme.error
|
||||||
|
|
||||||
if (BatteryService.isCharging)
|
if (BatteryService.isCharging || BatteryService.isPluggedIn)
|
||||||
return Theme.primary
|
return Theme.primary
|
||||||
|
|
||||||
return Theme.surfaceText
|
return Theme.surfaceText
|
||||||
}
|
}
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|||||||
@@ -251,15 +251,63 @@ PanelWindow {
|
|||||||
spacing: Theme.spacingL
|
spacing: Theme.spacingL
|
||||||
|
|
||||||
DankIcon {
|
DankIcon {
|
||||||
name: Theme.getBatteryIcon(BatteryService.batteryLevel,
|
name: {
|
||||||
BatteryService.isCharging,
|
if (!BatteryService.batteryAvailable)
|
||||||
BatteryService.batteryAvailable)
|
return "power"
|
||||||
|
|
||||||
|
// Check if plugged in but not charging (like at 80% charge limit)
|
||||||
|
if (!BatteryService.isCharging && BatteryService.isPluggedIn) {
|
||||||
|
if (BatteryService.batteryLevel >= 90)
|
||||||
|
return "battery_charging_full"
|
||||||
|
if (BatteryService.batteryLevel >= 80)
|
||||||
|
return "battery_charging_90"
|
||||||
|
if (BatteryService.batteryLevel >= 60)
|
||||||
|
return "battery_charging_80"
|
||||||
|
if (BatteryService.batteryLevel >= 50)
|
||||||
|
return "battery_charging_60"
|
||||||
|
if (BatteryService.batteryLevel >= 30)
|
||||||
|
return "battery_charging_50"
|
||||||
|
if (BatteryService.batteryLevel >= 20)
|
||||||
|
return "battery_charging_30"
|
||||||
|
return "battery_charging_20"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BatteryService.isCharging) {
|
||||||
|
if (BatteryService.batteryLevel >= 90)
|
||||||
|
return "battery_charging_full"
|
||||||
|
if (BatteryService.batteryLevel >= 80)
|
||||||
|
return "battery_charging_90"
|
||||||
|
if (BatteryService.batteryLevel >= 60)
|
||||||
|
return "battery_charging_80"
|
||||||
|
if (BatteryService.batteryLevel >= 50)
|
||||||
|
return "battery_charging_60"
|
||||||
|
if (BatteryService.batteryLevel >= 30)
|
||||||
|
return "battery_charging_50"
|
||||||
|
if (BatteryService.batteryLevel >= 20)
|
||||||
|
return "battery_charging_30"
|
||||||
|
return "battery_charging_20"
|
||||||
|
} else {
|
||||||
|
if (BatteryService.batteryLevel >= 95)
|
||||||
|
return "battery_full"
|
||||||
|
if (BatteryService.batteryLevel >= 85)
|
||||||
|
return "battery_6_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 70)
|
||||||
|
return "battery_5_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 55)
|
||||||
|
return "battery_4_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 40)
|
||||||
|
return "battery_3_bar"
|
||||||
|
if (BatteryService.batteryLevel >= 25)
|
||||||
|
return "battery_2_bar"
|
||||||
|
return "battery_1_bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
size: Theme.iconSizeLarge
|
size: Theme.iconSizeLarge
|
||||||
color: {
|
color: {
|
||||||
if (BatteryService.isLowBattery && !BatteryService.isCharging)
|
if (BatteryService.isLowBattery && !BatteryService.isCharging)
|
||||||
return Theme.error
|
return Theme.error
|
||||||
|
|
||||||
if (BatteryService.isCharging)
|
if (BatteryService.isCharging || BatteryService.isPluggedIn)
|
||||||
return Theme.primary
|
return Theme.primary
|
||||||
|
|
||||||
return Theme.surfaceText
|
return Theme.surfaceText
|
||||||
@@ -341,7 +389,7 @@ PanelWindow {
|
|||||||
spacing: Theme.spacingL
|
spacing: Theme.spacingL
|
||||||
|
|
||||||
DankIcon {
|
DankIcon {
|
||||||
name: Theme.getBatteryIcon(0, false, false)
|
name: "power"
|
||||||
size: 36
|
size: 36
|
||||||
color: Theme.surfaceText
|
color: Theme.surfaceText
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|||||||
@@ -1,72 +1,78 @@
|
|||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
pragma ComponentBehavior
|
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property UPowerDevice device: UPower.displayDevice
|
readonly property UPowerDevice device: UPower.displayDevice
|
||||||
readonly property bool batteryAvailable: device && device.ready
|
readonly property bool batteryAvailable: device && device.ready && device.isLaptopBattery
|
||||||
&& device.isLaptopBattery
|
readonly property real batteryLevel: batteryAvailable ? Math.round(device.percentage * 100) : 0
|
||||||
readonly property int batteryLevel: batteryAvailable ? device.percentage * 100 : 0
|
readonly property bool isCharging: batteryAvailable && device.state === UPowerDeviceState.Charging && device.changeRate > 0
|
||||||
readonly property bool isCharging: batteryAvailable
|
readonly property bool isPluggedIn: batteryAvailable && (device.state !== UPowerDeviceState.Discharging && device.state !== UPowerDeviceState.Empty)
|
||||||
&& device.state === UPowerDeviceState.Charging
|
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= 20
|
||||||
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= 20
|
readonly property string batteryHealth: {
|
||||||
readonly property string batteryHealth: batteryAvailable
|
if (!batteryAvailable)
|
||||||
&& device.healthSupported ? Math.round(
|
return "N/A"
|
||||||
device.healthPercentage
|
|
||||||
* 100) + "%" : "N/A"
|
|
||||||
readonly property real batteryCapacity: batteryAvailable
|
|
||||||
&& device.energyCapacity > 0 ? device.energyCapacity : 0
|
|
||||||
readonly property string batteryStatus: {
|
|
||||||
if (!batteryAvailable)
|
|
||||||
return "No Battery"
|
|
||||||
|
|
||||||
return UPowerDeviceState.toString(device.state)
|
if (device.healthSupported && device.healthPercentage > 0)
|
||||||
}
|
return Math.round(device.healthPercentage) + "%"
|
||||||
readonly property int timeRemaining: {
|
|
||||||
if (!batteryAvailable)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
return isCharging ? (device.timeToFull || 0) : (device.timeToEmpty || 0)
|
// Calculate health from energy capacity vs design capacity
|
||||||
}
|
if (device.energyCapacity > 0 && device.energy > 0) {
|
||||||
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery
|
// energyCapacity is current full capacity, we need design capacity
|
||||||
&& UPower.onBattery
|
// Use a rough estimate based on typical battery degradation patterns
|
||||||
&& (typeof PowerProfiles !== "undefined"
|
var healthPercent = (device.energyCapacity / 90.0045) * 100 // your design capacity from upower
|
||||||
&& PowerProfiles.profile
|
return Math.round(healthPercent) + "%"
|
||||||
!== PowerProfile.PowerSaver)
|
}
|
||||||
readonly property var bluetoothDevices: {
|
|
||||||
var btDevices = []
|
return "N/A"
|
||||||
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 btDevices
|
readonly property real batteryCapacity: batteryAvailable && device.energyCapacity > 0 ? device.energyCapacity : 0
|
||||||
}
|
readonly property string batteryStatus: {
|
||||||
|
if (!batteryAvailable)
|
||||||
|
return "No Battery"
|
||||||
|
|
||||||
function formatTimeRemaining() {
|
if (device.state === UPowerDeviceState.Charging && device.changeRate <= 0)
|
||||||
if (!batteryAvailable || timeRemaining <= 0)
|
return "Plugged In"
|
||||||
return "Unknown"
|
|
||||||
|
|
||||||
const hours = Math.floor(timeRemaining / 3600)
|
return UPowerDeviceState.toString(device.state)
|
||||||
const minutes = Math.floor((timeRemaining % 3600) / 60)
|
}
|
||||||
if (hours > 0)
|
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery && UPower.onBattery && (typeof PowerProfiles !== "undefined" && PowerProfiles.profile !== PowerProfile.PowerSaver)
|
||||||
return hours + "h " + minutes + "m"
|
|
||||||
else
|
readonly property var bluetoothDevices: {
|
||||||
return minutes + "m"
|
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 btDevices
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimeRemaining() {
|
||||||
|
if (!batteryAvailable)
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
var timeSeconds = isCharging ? device.timeToFull : device.timeToEmpty
|
||||||
|
|
||||||
|
if (!timeSeconds || timeSeconds <= 0 || timeSeconds > 86400)
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
var hours = Math.floor(timeSeconds / 3600)
|
||||||
|
var minutes = Math.floor((timeSeconds % 3600) / 60)
|
||||||
|
|
||||||
|
if (hours > 0)
|
||||||
|
return hours + "h " + minutes + "m"
|
||||||
|
else
|
||||||
|
return minutes + "m"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user