mirror of https://github.com/encounter/SDL.git
Don't fail to get battery status if the upower refresh call fails
This commit is contained in:
parent
c8cee0b8ca
commit
5c4fff7f63
|
@ -561,13 +561,20 @@ check_upower_device(DBusConnection *conn, const char *path, SDL_PowerState *stat
|
||||||
return;
|
return;
|
||||||
} else if (!ui32) {
|
} else if (!ui32) {
|
||||||
return; /* we don't care about random devices with batteries, like wireless controllers, etc */
|
return; /* we don't care about random devices with batteries, like wireless controllers, etc */
|
||||||
} else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "IsPresent", DBUS_TYPE_BOOLEAN, &ui32)) {
|
}
|
||||||
|
|
||||||
|
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "IsPresent", DBUS_TYPE_BOOLEAN, &ui32)) {
|
||||||
return;
|
return;
|
||||||
} else if (!ui32) {
|
}
|
||||||
|
if (!ui32) {
|
||||||
st = SDL_POWERSTATE_NO_BATTERY;
|
st = SDL_POWERSTATE_NO_BATTERY;
|
||||||
} else if (!SDL_DBus_CallMethodOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Refresh", DBUS_TYPE_INVALID, DBUS_TYPE_INVALID)) {
|
} else {
|
||||||
return;
|
/* Get updated information on the battery status
|
||||||
} else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "State", DBUS_TYPE_UINT32, &ui32)) {
|
* This can occasionally fail, and we'll just return slightly stale data in that case
|
||||||
|
*/
|
||||||
|
SDL_DBus_CallMethodOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Refresh", DBUS_TYPE_INVALID, DBUS_TYPE_INVALID);
|
||||||
|
|
||||||
|
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "State", DBUS_TYPE_UINT32, &ui32)) {
|
||||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||||
} else if (ui32 == 1) { /* 1 == charging */
|
} else if (ui32 == 1) { /* 1 == charging */
|
||||||
st = SDL_POWERSTATE_CHARGING;
|
st = SDL_POWERSTATE_CHARGING;
|
||||||
|
@ -578,6 +585,7 @@ check_upower_device(DBusConnection *conn, const char *path, SDL_PowerState *stat
|
||||||
} else {
|
} else {
|
||||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Percentage", DBUS_TYPE_DOUBLE, &d)) {
|
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Percentage", DBUS_TYPE_DOUBLE, &d)) {
|
||||||
pct = -1; /* some old/cheap batteries don't set this property. */
|
pct = -1; /* some old/cheap batteries don't set this property. */
|
||||||
|
|
Loading…
Reference in New Issue