Battery: fix low battery warning & fallback handling

This commit is contained in:
notiant
2026-01-29 21:24:35 +01:00
committed by GitHub
parent d164113f0c
commit ad310ec74b
6 changed files with 24 additions and 29 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
"Battery": {
"displayMode": "onhover",
"warningThreshold": 30,
"deviceNativePath": "",
"deviceNativePath": "__default__",
"showPowerProfiles": false,
"showNoctaliaPerformance": false,
"hideIfNotDetected": true,
+6 -6
View File
@@ -50,8 +50,8 @@ Item {
readonly property int testPercent: 35
readonly property bool testCharging: false
readonly property bool testPluggedIn: false
readonly property string deviceNativePath: widgetSettings.deviceNativePath || "__default__"
readonly property string deviceNativePath: widgetSettings.deviceNativePath !== undefined ? widgetSettings.deviceNativePath : widgetMetadata.deviceNativePath
readonly property var selectedBattery: BatteryService.findUPowerDevice(deviceNativePath)
readonly property var selectedBluetoothDevice: BatteryService.findBluetoothDevice(deviceNativePath)
readonly property var selectedDevice: {
@@ -61,7 +61,7 @@ Item {
if (BatteryService.isDevicePresent(selectedBattery)) {
return selectedBattery;
}
return BatteryService.primaryDevice;
return null;
}
// Check if selected device is actually present/connected
@@ -95,13 +95,13 @@ Item {
target: selectedDevice?.type === UPowerDeviceType.Battery ? selectedDevice : null
function onPercentageChanged() {
maybeNotify(BatteryService.getPercentage(selectedBattery), isCharging, isPluggedIn, isReady);
maybeNotify(BatteryService.getPercentage(selectedDevice), isCharging, isPluggedIn, isReady);
}
function onStateChanged() {
if (isCharging || isPluggedIn) {
hasNotifiedLowBattery = false;
}
maybeNotify(BatteryService.getPercentage(selectedBattery), isCharging, isPluggedIn, isReady);
maybeNotify(BatteryService.getPercentage(selectedDevice), isCharging, isPluggedIn, isReady);
}
}
@@ -109,7 +109,7 @@ Item {
target: selectedDevice?.batteryAvailable ? selectedDevice : null
function onBatteryChanged() {
maybeNotify(BatteryService.getPercentage(selectedBluetoothDevice), isCharging, isPluggedIn, isReady);
maybeNotify(BatteryService.getPercentage(selectedDevice), isCharging, isPluggedIn, isReady);
}
}
@@ -156,7 +156,7 @@ Item {
if (!isReady || !isPresent) {
return I18n.tr("battery.no-battery-detected");
}
const isInternal = selectedDevice === BatteryService.primaryDevice && BatteryService.isLaptopBattery;
const isInternal = selectedDevice.type === UPowerDeviceType.Battery && BatteryService.isLaptopBattery;
if (isInternal) {
let timeText = BatteryService.getTimeRemainingText(selectedDevice);
+2 -2
View File
@@ -35,7 +35,7 @@ SmartPanel {
if (BatteryService.isDevicePresent(selectedBattery)) {
return selectedBattery;
}
return BatteryService.primaryDevice;
return null;
}
// Check if selected device is actually present/connected
@@ -49,7 +49,7 @@ SmartPanel {
readonly property int healthPercent: (isReady && selectedBattery && selectedBattery.healthSupported) ? Math.round(selectedBattery.healthPercentage) : BatteryService.healthPercent
readonly property string deviceName: BatteryService.getDeviceName(selectedDevice)
readonly property string panelTitle: deviceName ? `${I18n.tr("common.battery")} - ${deviceName}` : I18n.tr("common.battery")
readonly property string panelTitle: deviceName ? `${deviceName}` : I18n.tr("common.battery")
readonly property var allDevices: {
var list = [];
@@ -18,7 +18,7 @@ ColumnLayout {
// Local state
property string valueDisplayMode: widgetData.displayMode !== undefined ? widgetData.displayMode : widgetMetadata.displayMode
property int valueWarningThreshold: widgetData.warningThreshold !== undefined ? widgetData.warningThreshold : widgetMetadata.warningThreshold
property string valueDeviceNativePath: widgetData.deviceNativePath !== undefined ? widgetData.deviceNativePath : ""
property string valueDeviceNativePath: widgetData.deviceNativePath !== undefined ? widgetData.deviceNativePath : "__default__"
property bool valueShowPowerProfiles: widgetData.showPowerProfiles !== undefined ? widgetData.showPowerProfiles : widgetMetadata.showPowerProfiles
property bool valueShowNoctaliaPerformance: widgetData.showNoctaliaPerformance !== undefined ? widgetData.showNoctaliaPerformance : widgetMetadata.showNoctaliaPerformance
property bool valueHideIfNotDetected: widgetData.hideIfNotDetected !== undefined ? widgetData.hideIfNotDetected : widgetMetadata.hideIfNotDetected
@@ -35,11 +35,7 @@ ColumnLayout {
settings.showNoctaliaPerformance = valueShowNoctaliaPerformance;
settings.hideIfNotDetected = valueHideIfNotDetected;
settings.hideIfIdle = valueHideIfIdle;
if (valueDeviceNativePath && valueDeviceNativePath !== "") {
settings.deviceNativePath = valueDeviceNativePath;
} else {
delete settings.deviceNativePath;
}
settings.deviceNativePath = valueDeviceNativePath;
return settings;
}
+12 -13
View File
@@ -59,6 +59,18 @@ Singleton {
return null;
}
readonly property var externalBatteries: {
var list = [];
var devices = BluetoothService.devices ? (BluetoothService.devices.values || []) : [];
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
if (device && device.connected && device.batteryAvailable) {
list.push(device);
}
}
return list;
}
readonly property var _bluetoothBattery: externalBatteries.length > 0 ? externalBatteries[0] : null
// MARK: BatterySettings
@@ -318,19 +330,6 @@ Singleton {
return I18n.tr("common.idle");
}
// MARK: BatteryPanel
readonly property var externalBatteries: {
var list = [];
var devices = BluetoothService.devices ? (BluetoothService.devices.values || []) : [];
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
if (device && device.connected && device.batteryAvailable) {
list.push(device);
}
}
return list;
}
// MARK: getTimeRemainingText
function getTimeRemainingText(device) {
if (!isDeviceReady(device)) {
+1 -1
View File
@@ -86,7 +86,7 @@ Singleton {
"Battery": {
"displayMode": "onhover",
"warningThreshold": 30,
"deviceNativePath": "",
"deviceNativePath": "__default__",
"showPowerProfiles": false,
"showNoctaliaPerformance": false,
"hideIfNotDetected": true,