kiran-control-panel/0003-fix-power-Fix-has-really-battery-while-it-is-present.patch

57 lines
1.6 KiB
Diff
Raw Normal View History

From 25384cbcc740634b4c3ee80026728a11603111cf Mon Sep 17 00:00:00 2001
From: meizhigang <meizhigang@kylinsec.com.cn>
Date: Mon, 8 Apr 2024 16:13:17 +0800
Subject: [PATCH 3/3] fix(power):Fix has really battery while it is present
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 适配真实电池存在场景
Related #31917
---
plugins/power/upower-interface.cpp | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/plugins/power/upower-interface.cpp b/plugins/power/upower-interface.cpp
index 4c964a6..4c04130 100644
--- a/plugins/power/upower-interface.cpp
+++ b/plugins/power/upower-interface.cpp
@@ -14,8 +14,8 @@
#include "upower-interface.h"
#include <upower.h>
-#include <cstdio>
#include <QtGlobal>
+#include <cstdio>
// 由于Glib定义与Qt内部相关定义冲突将该函数单独封装起来
bool UPowerInterface::haveBattery()
@@ -43,16 +43,21 @@ bool UPowerInterface::haveBattery()
#endif
void *device = nullptr;
UpDeviceKind kind;
+ gboolean is_present = FALSE;
for (unsigned int i = 0; i < devices->len; i++)
{
device = g_ptr_array_index(devices, i);
g_object_get(device,
"kind", &kind,
NULL);
- if (kind == UP_DEVICE_KIND_BATTERY)
+
+ g_object_get(device,
+ "is-present", &is_present,
+ NULL);
+ if (kind == UP_DEVICE_KIND_BATTERY && is_present)
hasBattery = true;
}
- g_ptr_array_unref (devices);
+ g_ptr_array_unref(devices);
g_object_unref(upClient);
return hasBattery;
}
--
2.27.0