Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor querying the battery percentage into a regular sysprop
  • Loading branch information
hrydgard committed Feb 11, 2025
commit ee772bb1e2e7f48657fd5c2750acba0e2d7abbab
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ add_library(Common STATIC
Common/SysError.cpp
Common/TimeUtil.cpp
Common/TimeUtil.h
Common/Battery/Battery.h
)

include_directories(Common)
Expand Down
5 changes: 2 additions & 3 deletions Common/Battery/AppleBatteryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Serena on 24/01/2023.
//

#include "Battery.h"
#import <Foundation/Foundation.h>

#if PPSSPP_PLATFORM(MAC)
Expand Down Expand Up @@ -90,7 +89,7 @@ - (void)setNeedsToUpdateLevel {

@end


int getCurrentBatteryCapacity() {
// TODO: Move this.
int Apple_GetCurrentBatteryCapacity() {
return [[AppleBatteryClient sharedClient] batteryLevel];
}
32 changes: 0 additions & 32 deletions Common/Battery/Battery.h

This file was deleted.

3 changes: 3 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions UI/DebugOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 5 additions & 6 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}

Expand Down
7 changes: 7 additions & 0 deletions ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ bool jb_enable_ptrace_hack(void) {
}
}

int Apple_GetCurrentBatteryCapacity();

int64_t System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down