From 819b79c8c101941dbaca486e2490808fcf700c92 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 26 Feb 2025 12:24:53 +0100 Subject: [PATCH] Fixed some issues with the system status indicators --- es-app/src/FileData.cpp | 2 +- es-app/src/guis/GuiSettings.cpp | 2 +- es-core/src/SystemStatus.h | 2 +- .../src/components/SystemStatusComponent.cpp | 27 ++++++++++++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 9e34e0e0d..260b95f79 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -2109,7 +2109,7 @@ returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBack if (!runInBackground) { window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); - SystemStatus::getInstance().pollImmediately(); + SystemStatus::getInstance().setPollImmediately(true); } // Update number of times the game has been launched. diff --git a/es-app/src/guis/GuiSettings.cpp b/es-app/src/guis/GuiSettings.cpp index d1e995c61..13636a7c7 100644 --- a/es-app/src/guis/GuiSettings.cpp +++ b/es-app/src/guis/GuiSettings.cpp @@ -147,7 +147,7 @@ void GuiSettings::save() if (mNeedsUpdateStatusComponents) { SystemStatus::getInstance().setCheckFlags(); - SystemStatus::getInstance().pollImmediately(); + SystemStatus::getInstance().setPollImmediately(true); // If we're not done within this time window it's not the end of the world, // the indicators will still get updated shortly. SDL_Delay(100); diff --git a/es-core/src/SystemStatus.h b/es-core/src/SystemStatus.h index f51d7752d..b22628449 100644 --- a/es-core/src/SystemStatus.h +++ b/es-core/src/SystemStatus.h @@ -22,7 +22,7 @@ public: void setCheckFlags(); void setPolling(const bool state); - void pollImmediately() { mPollImmediately = true; } + void setPollImmediately(const bool state) { mPollImmediately = state; } const bool getPollImmediately() { return mPollImmediately; } struct Status { diff --git a/es-core/src/components/SystemStatusComponent.cpp b/es-core/src/components/SystemStatusComponent.cpp index edc66ed29..9aa9cf5fe 100644 --- a/es-core/src/components/SystemStatusComponent.cpp +++ b/es-core/src/components/SystemStatusComponent.cpp @@ -82,7 +82,16 @@ void SystemStatusComponent::updateGrid() for (auto it = mDisplayEntries.cbegin(); it != mDisplayEntries.cend(); ++it) { if (*it == "battery") { mBattery = std::make_shared(false, true); - mBattery->setImage(mIconPathMap["battery_full"]); + if (mBatteryCharging) + mBattery->setImage(mIconPathMap["battery_charging"]); + else if (mBatteryCapacity >= 0 && mBatteryCapacity <= 25) + mBattery->setImage(mIconPathMap["battery_low"]); + else if (mBatteryCapacity >= 26 && mBatteryCapacity <= 60) + mBattery->setImage(mIconPathMap["battery_medium"]); + else if (mBatteryCapacity >= 61 && mBatteryCapacity <= 90) + mBattery->setImage(mIconPathMap["battery_high"]); + else + mBattery->setImage(mIconPathMap["battery_full"]); mBattery->setColorShift(mColorShift); mBattery->setResize(0, mSize.y); mBattery->setOpacity(mThemeOpacity); @@ -120,6 +129,7 @@ void SystemStatusComponent::updateGrid() width += mBatteryPercentage->getSize().x; mEntryMap["batteryText"] = i; mGrid->setEntry(mBatteryPercentage, glm::ivec2 {i, 0}, false, false); + mBatteryPercentage->setValue(std::to_string(mBatteryCapacity) + "%"); } for (int i {0}; i < static_cast(mGrid->getChildCount()); ++i) { @@ -290,10 +300,12 @@ void SystemStatusComponent::update(int deltaTime) #if defined(__ANDROID__) // For Android we poll on the main thread instead of in a separate thread. SystemStatus::Status status; - if (mAccumulatorAndroid >= SystemStatus::pollingTime || - SystemStatus::getInstance().getPollImmediately()) { + const bool pollImmediately {SystemStatus::getInstance().getPollImmediately()}; + if (mAccumulatorAndroid >= SystemStatus::pollingTime || pollImmediately) { status = SystemStatus::getInstance().getStatus(true); mAccumulatorAndroid = 0; + if (pollImmediately) + SystemStatus::getInstance().setPollImmediately(false); } else { status = SystemStatus::getInstance().getStatus(false); @@ -332,10 +344,13 @@ void SystemStatusComponent::update(int deltaTime) batteryStatusChanged = true; } - if (statusChanged) + if (statusChanged) { updateGrid(); - - if (mHasBattery && batteryStatusChanged) { + } + else if (mHasBattery && batteryStatusChanged) { + // Slight optimization, just update the battery charge percentage and icon in + // case only the battery status has changed, instead of having to recreate the + // entire grid when this happens. if (mBatteryPercentage != nullptr) mBatteryPercentage->setValue(std::to_string(mBatteryCapacity) + "%");