From 3388ded91b2091cb63c62b54cfe639fc53d5b53a Mon Sep 17 00:00:00 2001 From: oh_ci Date: Tue, 25 Feb 2025 10:07:17 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!657=20:?= =?UTF-8?q?=20fix:=20Charging=E8=BF=94=E5=9B=9E=E5=80=BC=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/napi/include/system_battery.h | 2 +- frameworks/napi/src/battery_info.cpp | 2 +- frameworks/napi/src/system_battery.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/napi/include/system_battery.h b/frameworks/napi/include/system_battery.h index 325f5f0..7239cf9 100644 --- a/frameworks/napi/include/system_battery.h +++ b/frameworks/napi/include/system_battery.h @@ -57,7 +57,7 @@ private: public: bool GetBatteryInfo(); double GetLevel() const; - bool IsCharging() const; + uint32_t IsCharging() const; private: int32_t capacity_ { INVALID_BATT_INT_VALUE }; diff --git a/frameworks/napi/src/battery_info.cpp b/frameworks/napi/src/battery_info.cpp index 5c956eb..51e9558 100644 --- a/frameworks/napi/src/battery_info.cpp +++ b/frameworks/napi/src/battery_info.cpp @@ -263,7 +263,7 @@ static napi_value IsBatteryConfigSupported(napi_env env, napi_callback_info info BATTERY_HILOGI(COMP_FWK, "get support charge config, sceneValue: %{public}d", static_cast(result)); napi_value napiValue; - NAPI_CALL(env, napi_get_boolean(env, result, &napiValue)); + NAPI_CALL(env, napi_create_uint32(env, static_cast(result), &napiValue)); if (code != BatteryError::ERR_OK) { error.ThrowError(env, code); return napiValue; diff --git a/frameworks/napi/src/system_battery.cpp b/frameworks/napi/src/system_battery.cpp index fa8652f..f5ff657 100644 --- a/frameworks/napi/src/system_battery.cpp +++ b/frameworks/napi/src/system_battery.cpp @@ -63,7 +63,7 @@ napi_value SystemBattery::CreateResponse(napi_env env) napi_value level = nullptr; napi_value charging = nullptr; NAPI_CALL(env, napi_create_double(env, batteryInfo_.GetLevel(), &level)); - NAPI_CALL(env, napi_get_boolean(env, batteryInfo_.IsCharging(), &charging)); + NAPI_CALL(env, napi_create_uint32(env, batteryInfo_.IsCharging(), &charging)); napi_value response = nullptr; NAPI_CALL(env, napi_create_object(env, &response)); @@ -210,10 +210,10 @@ double SystemBattery::BatteryInfo::GetLevel() const return (capacity_ * LEVEL_RANGES); } -bool SystemBattery::BatteryInfo::IsCharging() const +uint32_t SystemBattery::BatteryInfo::IsCharging() const { - return chargingState_ == BatteryChargeState::CHARGE_STATE_ENABLE || - chargingState_ == BatteryChargeState::CHARGE_STATE_FULL; + return static_cast(chargingState_ == BatteryChargeState::CHARGE_STATE_ENABLE || + chargingState_ == BatteryChargeState::CHARGE_STATE_FULL); } static void SendEvent(napi_env env, SystemBattery *asyncContext, napi_event_priority prio) -- Gitee