mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 15:32:50 -05:00
Systematic cleanup and qmlfmt of all services
- qmlfmt kinda sucks but it's what qt creator uses
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
pragma ComponentBehavior
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
@@ -9,68 +10,50 @@ Singleton {
|
||||
id: root
|
||||
|
||||
readonly property UPowerDevice device: UPower.displayDevice
|
||||
readonly property bool batteryAvailable: device && device.ready
|
||||
&& device.isLaptopBattery
|
||||
readonly property real batteryLevel: batteryAvailable ? Math.round(
|
||||
device.percentage * 100) : 0
|
||||
readonly property bool isCharging: batteryAvailable
|
||||
&& device.state === UPowerDeviceState.Charging
|
||||
&& device.changeRate > 0
|
||||
readonly property bool isPluggedIn: batteryAvailable
|
||||
&& (device.state !== UPowerDeviceState.Discharging
|
||||
&& device.state !== UPowerDeviceState.Empty)
|
||||
readonly property bool batteryAvailable: device && device.ready && device.isLaptopBattery
|
||||
readonly property real batteryLevel: batteryAvailable ? Math.round(device.percentage * 100) : 0
|
||||
readonly property bool isCharging: batteryAvailable && device.state === UPowerDeviceState.Charging && device.changeRate > 0
|
||||
readonly property bool isPluggedIn: batteryAvailable && (device.state !== UPowerDeviceState.Discharging && device.state !== UPowerDeviceState.Empty)
|
||||
readonly property bool isLowBattery: batteryAvailable && batteryLevel <= 20
|
||||
readonly property string batteryHealth: {
|
||||
if (!batteryAvailable)
|
||||
return "N/A"
|
||||
if (!batteryAvailable) {
|
||||
return "N/A"
|
||||
}
|
||||
|
||||
if (device.healthSupported && device.healthPercentage > 0)
|
||||
return Math.round(device.healthPercentage) + "%"
|
||||
if (device.healthSupported && device.healthPercentage > 0) {
|
||||
return `${Math.round(device.healthPercentage)}%`
|
||||
}
|
||||
|
||||
// Calculate health from energy capacity vs design capacity
|
||||
if (device.energyCapacity > 0 && device.energy > 0) {
|
||||
// energyCapacity is current full capacity, we need design capacity
|
||||
// Use a rough estimate based on typical battery degradation patterns
|
||||
var healthPercent = (device.energyCapacity / 90.0045)
|
||||
* 100 // your design capacity from upower
|
||||
return Math.round(healthPercent) + "%"
|
||||
const healthPercent = (device.energyCapacity / 90.0045) * 100
|
||||
return `${Math.round(healthPercent)}%`
|
||||
}
|
||||
|
||||
return "N/A"
|
||||
}
|
||||
readonly property real batteryCapacity: batteryAvailable
|
||||
&& device.energyCapacity > 0 ? device.energyCapacity : 0
|
||||
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 (device.state === UPowerDeviceState.Charging
|
||||
&& device.changeRate <= 0)
|
||||
return "Plugged In"
|
||||
if (device.state === UPowerDeviceState.Charging && device.changeRate <= 0) {
|
||||
return "Plugged In"
|
||||
}
|
||||
|
||||
return UPowerDeviceState.toString(device.state)
|
||||
}
|
||||
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery
|
||||
&& UPower.onBattery
|
||||
&& (typeof PowerProfiles !== "undefined"
|
||||
&& PowerProfiles.profile
|
||||
!== PowerProfile.PowerSaver)
|
||||
readonly property bool suggestPowerSaver: batteryAvailable && isLowBattery && UPower.onBattery && (typeof PowerProfiles !== "undefined" && PowerProfiles.profile !== PowerProfile.PowerSaver)
|
||||
|
||||
readonly property var bluetoothDevices: {
|
||||
var btDevices = []
|
||||
const btDevices = []
|
||||
const bluetoothTypes = [UPowerDeviceType.BluetoothGeneric, UPowerDeviceType.Headphones, UPowerDeviceType.Headset, UPowerDeviceType.Keyboard, UPowerDeviceType.Mouse, UPowerDeviceType.Speakers]
|
||||
|
||||
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)) {
|
||||
const dev = UPower.devices.get(i)
|
||||
if (dev && dev.ready && bluetoothTypes.includes(dev.type)) {
|
||||
btDevices.push({
|
||||
"name": dev.model
|
||||
|| UPowerDeviceType.toString(
|
||||
dev.type),
|
||||
"name": dev.model || UPowerDeviceType.toString(dev.type),
|
||||
"percentage": Math.round(dev.percentage),
|
||||
"type": dev.type
|
||||
})
|
||||
@@ -80,20 +63,23 @@ Singleton {
|
||||
}
|
||||
|
||||
function formatTimeRemaining() {
|
||||
if (!batteryAvailable)
|
||||
if (!batteryAvailable) {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
var timeSeconds = isCharging ? device.timeToFull : device.timeToEmpty
|
||||
const timeSeconds = isCharging ? device.timeToFull : device.timeToEmpty
|
||||
|
||||
if (!timeSeconds || timeSeconds <= 0 || timeSeconds > 86400)
|
||||
if (!timeSeconds || timeSeconds <= 0 || timeSeconds > 86400) {
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
var hours = Math.floor(timeSeconds / 3600)
|
||||
var minutes = Math.floor((timeSeconds % 3600) / 60)
|
||||
const hours = Math.floor(timeSeconds / 3600)
|
||||
const minutes = Math.floor((timeSeconds % 3600) / 60)
|
||||
|
||||
if (hours > 0)
|
||||
return hours + "h " + minutes + "m"
|
||||
else
|
||||
return minutes + "m"
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`
|
||||
}
|
||||
|
||||
return `${minutes}m`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user