mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Revert "battery: new stuff from turannul"
This reverts commit a14d80abdd.
This commit is contained in:
@@ -62,23 +62,16 @@ Item {
|
||||
}
|
||||
readonly property bool hasBluetoothBattery: BatteryService.isBluetoothDevice(device)
|
||||
|
||||
readonly property bool isReady: testMode ? true : (initializationComplete && BatteryService.isDeviceReady(device))
|
||||
readonly property bool isReady: testMode ? true : (BatteryService.ready && BatteryService.isDeviceReady(device))
|
||||
readonly property real percent: testMode ? testPercent : (isReady ? BatteryService.getPercentage(device) : 0)
|
||||
readonly property bool isCharging: testMode ? testCharging : (isReady ? BatteryService.isCharging(device) : false)
|
||||
readonly property bool isPluggedIn: testMode ? testPluggedIn : (isReady ? BatteryService.isPluggedIn(device) : false)
|
||||
|
||||
property bool initializationComplete: false
|
||||
property bool hasNotifiedLowBattery: false
|
||||
|
||||
visible: shouldShow
|
||||
opacity: shouldShow ? 1.0 : 0.0
|
||||
|
||||
Timer {
|
||||
interval: 500
|
||||
running: true
|
||||
onTriggered: root.initializationComplete = true
|
||||
}
|
||||
|
||||
readonly property bool isDevicePresent: {
|
||||
if (testMode)
|
||||
return true;
|
||||
@@ -104,7 +97,7 @@ Item {
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: (device && !BatteryService.isBluetoothDevice(device)) ? device : null
|
||||
target: device
|
||||
function onPercentageChanged() {
|
||||
if (device) {
|
||||
maybeNotify(getCurrentPercent(), isCharging, isPluggedIn, isReady);
|
||||
@@ -123,11 +116,6 @@ Item {
|
||||
|
||||
Connections {
|
||||
target: (device && BatteryService.isBluetoothDevice(device)) ? device : null
|
||||
function onBatteryChanged() {
|
||||
if (device) {
|
||||
maybeNotify(getCurrentPercent(), isCharging, isPluggedIn, isReady);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NPopupContextMenu {
|
||||
@@ -160,9 +148,9 @@ Item {
|
||||
suffix: "%"
|
||||
autoHide: false
|
||||
forceOpen: isReady && displayMode === "alwaysShow"
|
||||
forceClose: displayMode === "alwaysHide" || (initializationComplete && !isReady)
|
||||
customBackgroundColor: !initializationComplete ? "transparent" : (isCharging ? Color.mPrimary : (isLowBattery ? Color.mError : "transparent"))
|
||||
customTextIconColor: !initializationComplete ? "transparent" : (isCharging ? Color.mOnPrimary : (isLowBattery ? Color.mOnError : "transparent"))
|
||||
forceClose: displayMode === "alwaysHide" || (BatteryService.ready && !isReady)
|
||||
customBackgroundColor: !BatteryService.ready ? "transparent" : (isCharging ? Color.mPrimary : (isLowBattery ? Color.mError : "transparent"))
|
||||
customTextIconColor: !BatteryService.ready ? "transparent" : (isCharging ? Color.mOnPrimary : (isLowBattery ? Color.mOnError : "transparent"))
|
||||
|
||||
tooltipText: {
|
||||
let lines = [];
|
||||
|
||||
@@ -4,6 +4,7 @@ import QtQuick.Layouts
|
||||
import qs.Commons
|
||||
import qs.Services.Hardware
|
||||
import qs.Widgets
|
||||
import qs.Services.Hardware
|
||||
|
||||
ColumnLayout {
|
||||
id: root
|
||||
@@ -13,6 +14,8 @@ ColumnLayout {
|
||||
property var widgetData: null
|
||||
property var widgetMetadata: null
|
||||
|
||||
signal settingsChanged(var settings)
|
||||
|
||||
// Local state
|
||||
property string valueDisplayMode: widgetData.displayMode !== undefined ? widgetData.displayMode : widgetMetadata.displayMode
|
||||
property int valueWarningThreshold: widgetData.warningThreshold !== undefined ? widgetData.warningThreshold : widgetMetadata.warningThreshold
|
||||
@@ -55,7 +58,10 @@ ColumnLayout {
|
||||
minimumWidth: 200
|
||||
model: root.deviceModel
|
||||
currentKey: root.valueDeviceNativePath
|
||||
onSelected: key => root.valueDeviceNativePath = key
|
||||
onSelected: key => {
|
||||
root.valueDeviceNativePath = key;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
// Update currentKey when model changes to ensure selection is preserved
|
||||
@@ -69,15 +75,17 @@ ColumnLayout {
|
||||
|
||||
NIconButton {
|
||||
icon: "refresh"
|
||||
// TODO i18n
|
||||
tooltipText: "Refresh device list"
|
||||
onClicked: BatteryService.devicesModel = BatteryService.buildDeviceModel()
|
||||
}
|
||||
}
|
||||
|
||||
NComboBox {
|
||||
Layout.fillWidth: true
|
||||
label: I18n.tr("bar.volume.display-mode-label")
|
||||
description: I18n.tr("bar.volume.display-mode-description")
|
||||
minimumWidth: 134
|
||||
minimumWidth: 240
|
||||
model: [
|
||||
{
|
||||
"key": "onhover",
|
||||
@@ -93,7 +101,10 @@ ColumnLayout {
|
||||
}
|
||||
]
|
||||
currentKey: root.valueDisplayMode
|
||||
onSelected: key => root.valueDisplayMode = key
|
||||
onSelected: key => {
|
||||
root.valueDisplayMode = key;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
NSpinBox {
|
||||
@@ -103,34 +114,49 @@ ColumnLayout {
|
||||
suffix: "%"
|
||||
minimum: 5
|
||||
maximum: 50
|
||||
onValueChanged: valueWarningThreshold = value
|
||||
onValueChanged: {
|
||||
valueWarningThreshold = value;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
NToggle {
|
||||
label: I18n.tr("bar.battery.show-power-profile-label")
|
||||
description: I18n.tr("bar.battery.show-power-profile-description")
|
||||
checked: valueShowPowerProfiles
|
||||
onToggled: checked => valueShowPowerProfiles = checked
|
||||
onToggled: checked => {
|
||||
valueShowPowerProfiles = checked;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
NToggle {
|
||||
label: I18n.tr("bar.battery.show-noctalia-performance-label")
|
||||
description: I18n.tr("bar.battery.show-noctalia-performance-description")
|
||||
checked: valueShowNoctaliaPerformance
|
||||
onToggled: checked => valueShowNoctaliaPerformance = checked
|
||||
onToggled: checked => {
|
||||
valueShowNoctaliaPerformance = checked;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
NToggle {
|
||||
label: I18n.tr("bar.battery.hide-if-not-detected-label")
|
||||
description: I18n.tr("bar.battery.hide-if-not-detected-description")
|
||||
checked: valueHideIfNotDetected
|
||||
onToggled: checked => valueHideIfNotDetected = checked
|
||||
onToggled: checked => {
|
||||
valueHideIfNotDetected = checked;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
|
||||
NToggle {
|
||||
label: I18n.tr("bar.battery.hide-if-idle-label")
|
||||
description: I18n.tr("bar.battery.hide-if-idle-description")
|
||||
checked: valueHideIfIdle
|
||||
onToggled: checked => valueHideIfIdle = checked
|
||||
onToggled: checked => {
|
||||
valueHideIfIdle = checked;
|
||||
settingsChanged(saveSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,17 @@ Singleton {
|
||||
if (!UPower.devices)
|
||||
return UPower.displayDevice;
|
||||
|
||||
var devices = UPower.devices.values || [];
|
||||
// 2. Determine the primary device (System Battery)
|
||||
readonly property var primaryDevice: {
|
||||
if (devices.length === 0)
|
||||
return null;
|
||||
|
||||
// 1. Explicitly look for BAT0 first
|
||||
// Prioritize DisplayDevice (Aggregate)
|
||||
if (UPower.displayDevice && UPower.displayDevice.type === UPowerDeviceType.Battery && isDevicePresent(UPower.displayDevice)) {
|
||||
return UPower.displayDevice;
|
||||
}
|
||||
|
||||
// Prioritize BAT0
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
var d = devices[i];
|
||||
if (d && (d.nativePath === "BAT0" || d.objectPath === "/org/freedesktop/UPower/devices/battery_BAT0")) {
|
||||
@@ -39,16 +47,11 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback to displayDevice if it's a laptop battery
|
||||
if (UPower.displayDevice && UPower.displayDevice.isLaptopBattery) {
|
||||
return UPower.displayDevice;
|
||||
}
|
||||
|
||||
// 3. Any other device marked as a laptop battery
|
||||
// Prioritize (any) Laptop Battery
|
||||
for (var j = 0; j < devices.length; j++) {
|
||||
var device = devices[j];
|
||||
if (device && device.type === UPowerDeviceType.Battery && device.isLaptopBattery) {
|
||||
return device;
|
||||
var dev = devices[j];
|
||||
if (dev && !isBluetoothDevice(dev) && dev.isLaptopBattery) {
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,21 +95,11 @@ Singleton {
|
||||
return _laptopBattery;
|
||||
}
|
||||
|
||||
if (!UPower.devices) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var deviceArray = UPower.devices.values || [];
|
||||
for (var i = 0; i < deviceArray.length; i++) {
|
||||
var device = deviceArray[i];
|
||||
if (device && device.nativePath === nativePath) {
|
||||
if (device.type === UPowerDeviceType.LinePower) {
|
||||
continue;
|
||||
}
|
||||
return device;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
Timer {
|
||||
interval: 500
|
||||
running: true
|
||||
repeat: false
|
||||
onTriggered: root.initializationComplete = true
|
||||
}
|
||||
|
||||
// MARK: findBluetoothDevice
|
||||
@@ -115,18 +108,23 @@ Singleton {
|
||||
return null;
|
||||
}
|
||||
|
||||
var macMatch = nativePath.match(/([0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2})/);
|
||||
if (!macMatch) {
|
||||
return null;
|
||||
// Check for DisplayDevice explicitly if requested via "DisplayDevice" or empty string
|
||||
if (nativePath === "DisplayDevice" && UPower.displayDevice) {
|
||||
return UPower.displayDevice;
|
||||
}
|
||||
|
||||
var macAddress = macMatch[1].toUpperCase();
|
||||
var deviceArray = BluetoothService.devices.values || [];
|
||||
|
||||
for (var i = 0; i < deviceArray.length; i++) {
|
||||
var device = deviceArray[i];
|
||||
if (device && device.address && device.address.toUpperCase() === macAddress) {
|
||||
return device;
|
||||
// Search in our cached list
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
var d = devices[i];
|
||||
if (isBluetoothDevice(d)) {
|
||||
if (d.address && d.address.toUpperCase() === nativePath.toUpperCase())
|
||||
return d;
|
||||
// Try matching MAC in path string if passed format differs
|
||||
if (nativePath.includes(d.address.toUpperCase()))
|
||||
return d;
|
||||
} else {
|
||||
if (d.nativePath === nativePath)
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -137,7 +135,7 @@ Singleton {
|
||||
if (!device)
|
||||
return false;
|
||||
|
||||
// Handle Bluetooth devices (identified by having batteryAvailable property)
|
||||
// Handle Bluetooth devices
|
||||
if (device.batteryAvailable !== undefined) {
|
||||
return device.connected === true;
|
||||
}
|
||||
@@ -147,11 +145,8 @@ Singleton {
|
||||
if (device.type === UPowerDeviceType.Battery && device.isPresent !== undefined) {
|
||||
return device.isPresent === true;
|
||||
}
|
||||
|
||||
// Fallback for non-battery UPower devices or if isPresent is missing
|
||||
return device.ready && device.percentage !== undefined;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -163,7 +158,6 @@ Singleton {
|
||||
if (device.batteryAvailable !== undefined) {
|
||||
return device.battery !== undefined;
|
||||
}
|
||||
|
||||
return device.ready && device.percentage !== undefined;
|
||||
}
|
||||
|
||||
@@ -263,7 +257,7 @@ Singleton {
|
||||
Qt.callLater(refreshHealth);
|
||||
}
|
||||
}
|
||||
// MARK: getIcon
|
||||
// MARK: getIcon
|
||||
function getIcon(percent, charging, pluggedIn, isReady) {
|
||||
if (!isReady) {
|
||||
return "battery-exclamation";
|
||||
@@ -297,6 +291,7 @@ Singleton {
|
||||
return primaryDevice !== null;
|
||||
}
|
||||
|
||||
|
||||
// MARK: Battery
|
||||
// MARK: getRateText
|
||||
function getRateText(device) {
|
||||
@@ -317,6 +312,7 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: BatteryPanel
|
||||
readonly property var externalBatteries: {
|
||||
var list = [];
|
||||
@@ -353,14 +349,14 @@ Singleton {
|
||||
return I18n.tr("common.idle");
|
||||
}
|
||||
|
||||
|
||||
// MARK: BatterySettings
|
||||
property var devicesModel: buildDeviceModel()
|
||||
|
||||
function buildDeviceModel() {
|
||||
var model = [
|
||||
{
|
||||
"key": UPower.devices.DisplayDevice || "" // It was capital D and i spend an hour to figure out [why tf this do absolutely nothing] XD (I hate my left shift it sticks)
|
||||
,
|
||||
"key": UPower.devices.DisplayDevice || "", // It was capital D and i spend an hour to figure out [why tf this do absolutely nothing] XD (I hate my left shift it sticks)
|
||||
"name": I18n.tr("bar.battery.device-default")
|
||||
}
|
||||
];
|
||||
@@ -375,9 +371,9 @@ Singleton {
|
||||
}
|
||||
var displayName = device.model || device.nativePath || "Unknown";
|
||||
model.push({
|
||||
"key": device.nativePath || "",
|
||||
"name": displayName
|
||||
});
|
||||
"key": device.nativePath || "",
|
||||
"name": displayName
|
||||
});
|
||||
}
|
||||
}
|
||||
return model;
|
||||
@@ -400,9 +396,6 @@ Singleton {
|
||||
|
||||
Connections {
|
||||
target: UPower.devices
|
||||
function onValuesChanged() {
|
||||
modelUpdateTimer.restart();
|
||||
devicesModel = buildDeviceModel();
|
||||
}
|
||||
function onValuesChanged() { modelUpdateTimer.restart(); devicesModel = buildDeviceModel(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user