Refactor querying the battery percentage into a regular sysprop

This commit is contained in:
Henrik Rydgård committed 2025-02-11 10:31:18 -06:00
1 parent 57a91e1f74
commit ee772bb1e2
8 files changed
+33 -48

No files matched your search

-1
View File
@@ -926,7 +926,6 @@ add_library(Common STATIC
Common/SysError.cpp
Common/TimeUtil.cpp
Common/TimeUtil.h
Common/Battery/Battery.h
)
include_directories(Common)
+2 -3
View File
@@ -5,7 +5,6 @@
// Created by Serena on 24/01/2023.
//
#include "Battery.h"
#import <Foundation/Foundation.h>
#if PPSSPP_PLATFORM(MAC)
@@ -90,7 +89,7 @@ void _powerSourceRunLoopCallback(void * __unused ctx) {
@end
int getCurrentBatteryCapacity() {
// TODO: Move this.
int Apple_GetCurrentBatteryCapacity() {
return [[AppleBatteryClient sharedClient] batteryLevel];
}
-32
View File
@@ -1,32 +0,0 @@
//
// Battery.h
// PPSSPP
//
// Created by Serena on 24/01/2023.
//
// NOTE: Though this is a general purpose header file,
// though the implementation right now is Darwin specific
// In case any future platform implementations are made for other platforms,
// define the function below in their own file
#ifndef BATTERY_H
#define BATTERY_H
#include "ppsspp_config.h"
//#include <Foundation/Foundation.h>
#ifdef __cplusplus
extern "C" {
#endif
#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC)
#define CAN_DISPLAY_CURRENT_BATTERY_CAPACITY
/// Get the current battery %.
int getCurrentBatteryCapacity();
#endif /* PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC) */
#ifdef __cplusplus
}
#endif
#endif /* BATTERY_H */
+3
View File
@@ -213,6 +213,9 @@ enum SystemProperty {
SYSPROP_OK_BUTTON_LEFT,
SYSPROP_MAIN_WINDOW_HANDLE,
SYSPROP_CAN_READ_BATTERY_PERCENTAGE,
SYSPROP_BATTERY_PERCENTAGE,
};
enum class SystemNotification {
+9
View File
@@ -513,6 +513,10 @@ std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
}
}
#if PPSSPP_PLATFORM(MAC)
int Apple_GetCurrentBatteryCapacity();
#endif
int64_t System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
@@ -543,6 +547,10 @@ int64_t System_GetPropertyInt(SystemProperty prop) {
return g_DesktopWidth;
case SYSPROP_DISPLAY_YRES:
return g_DesktopHeight;
#if PPSSPP_PLATFORM(MAC)
case SYSPROP_BATTERY_PERCENTAGE:
return Apple_GetCurrentBatteryCapacity();
#endif
default:
return -1;
}
@@ -604,6 +612,7 @@ bool System_GetPropertyBool(SystemProperty prop) {
#if PPSSPP_PLATFORM(MAC)
case SYSPROP_HAS_FOLDER_BROWSER:
case SYSPROP_HAS_FILE_BROWSER:
case SYSPROP_CAN_READ_BATTERY_PERCENTAGE:
return true;
#endif
case SYSPROP_HAS_ACCELEROMETER:
+7 -6
View File
@@ -453,13 +453,14 @@ void DrawFPS(UIContext *ctx, const Bounds &bounds) {
}
}
#ifdef CAN_DISPLAY_CURRENT_BATTERY_CAPACITY
if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::BATTERY_PERCENT) {
char temp[256];
snprintf(temp, sizeof(temp), "%s Battery: %d%%", fpsbuf, getCurrentBatteryCapacity());
snprintf(fpsbuf, sizeof(fpsbuf), "%s", temp);
if (System_GetPropertyBool(SYSPROP_CAN_READ_BATTERY_PERCENTAGE)) {
if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::BATTERY_PERCENT) {
char temp[256];
const int percentage = System_GetPropertyInt(SYSPROP_BATTERY_PERCENTAGE);
snprintf(temp, sizeof(temp), "%s Battery: %d%%", fpsbuf, percentage);
snprintf(fpsbuf, sizeof(fpsbuf), "%s", temp);
}
}
#endif
ctx->Flush();
ctx->BindFontTexture();
+5 -6
View File
@@ -33,7 +33,6 @@
#include "Common/System/Display.h" // Only to check screen aspect ratio with pixel_yres/pixel_xres
#include "Common/System/Request.h"
#include "Common/System/OSD.h"
#include "Common/Battery/Battery.h"
#include "Common/System/NativeApp.h"
#include "Common/Data/Color/RGBAUtil.h"
#include "Common/Math/curves.h"
@@ -622,11 +621,11 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
});
graphicsSettings->Add(new ItemHeader(gr->T("Overlay Information")));
BitCheckBox *showFPSCtr = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::FPS_COUNTER, gr->T("Show FPS Counter")));
BitCheckBox *showSpeed = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::SPEED_COUNTER, gr->T("Show Speed")));
#ifdef CAN_DISPLAY_CURRENT_BATTERY_CAPACITY
BitCheckBox *showBattery = graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::BATTERY_PERCENT, gr->T("Show Battery %")));
#endif
graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::FPS_COUNTER, gr->T("Show FPS Counter")));
graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::SPEED_COUNTER, gr->T("Show Speed")));
if (System_GetPropertyBool(SYSPROP_CAN_READ_BATTERY_PERCENTAGE)) {
graphicsSettings->Add(new BitCheckBox(&g_Config.iShowStatusFlags, (int)ShowStatusFlags::BATTERY_PERCENT, gr->T("Show Battery %")));
}
AddOverlayList(graphicsSettings, screenManager());
}
+7
View File
@@ -316,6 +316,8 @@ std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
}
}
int Apple_GetCurrentBatteryCapacity();
int64_t System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
@@ -324,6 +326,8 @@ int64_t System_GetPropertyInt(SystemProperty prop) {
return DEVICE_TYPE_MOBILE;
case SYSPROP_SYSTEMVERSION:
return g_iosVersionMajor;
case SYSPROP_BATTERY_PERCENTAGE:
return Apple_GetCurrentBatteryCapacity();
default:
return -1;
}
@@ -381,6 +385,9 @@ bool System_GetPropertyBool(SystemProperty prop) {
case SYSPROP_SUPPORTS_HTTPS:
return true;
#endif
case SYSPROP_CAN_READ_BATTERY_PERCENTAGE:
return true;
default:
return false;
}