Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon/detect-android-batt-saver #5262

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Conversation

Jon-edge
Copy link
Collaborator

@Jon-edge Jon-edge commented Sep 18, 2024

image

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

previousState = state
}

await checkPowerSavingMode()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just inline the function. No need to declare it then call it.


const checkPowerSavingMode = async () => {
// This method is only available for Android
if (powerSavingOn != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check at the top of the useAsyncEffect

if (Platform.OS !== 'android') return

This eliminates all the checks for powerSavingOn or powerSavingModeChanged

Copy link
Collaborator Author

@Jon-edge Jon-edge Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider this when I wrote the PR

Those functions are defined as optional by the lib, I'd still need to check for the existence of the function even if I made this change.

To implement your suggestion and not check for the function existence, I'd need to also patch the lib's source itself. The way I had it seemed like the simpler approach in case the contents of the lib change in the future.

}

const handlePowerSavingModeChanged = async (state: boolean) => {
if (state && !previousState) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have a previousState. showBatterySaverWarning already checks if it's showing and early exits.

@Jon-edge
Copy link
Collaborator Author

Also fixed auto-dismissing the warning when battery saver was turned off but the user never previously manually dismissed the warning

airshipBridge = undefined
})
} else if (airshipBridge != null) {
// Dismiss the alert when power-saving mode turns off and there's an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause the alert to be dismissed if isPowerSavingModeOn and the modal is showing. While you shouldn't get this case, you are relying on distributed logic to ensure this doesn't break. Logic in the SDK in addition to logic in your code.

This should be

if (isPowerSavingModeOn && airshipBridge == null) {
   // showmodal
} else if (!isPowerSavingModeOn && airshipBridge != null) {
    // close modal
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I originally had it like this but assumed you'd prefer it less verbose since it shouldn't happen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbose isn't bad if it makes the logic crystal clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to hear, that's my preference too

@Jon-edge Jon-edge merged commit 15f5719 into develop Sep 27, 2024
2 checks passed
@Jon-edge Jon-edge deleted the jon/detect-android-batt-saver branch September 27, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants