EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep
264 stars 106 forks source link

describe behaviour when calling allowSleepAgain without calling keepAwake in advance #49

Closed prompteus closed 6 years ago

prompteus commented 6 years ago

According to my experience (ios devices) allowSleepAgain causes app crash if keepAwake wasn't called in advance. I do not think this behaviour has to change, but I think it should be mentioned in Readme.

EddyVerbruggen commented 6 years ago

What's 'enableSleepAwake'?

And if you want to add something to the readme, please feel free to submit a PR.

prompteus commented 6 years ago

My mistake, I've used bad method name here, so I updated the issue. I meant allowSleepAgain.

EddyVerbruggen commented 6 years ago

Yeah, I thought that order would be pretty obvious. But the plugin could perhaps harden against 'bad' usage patterns.

Which platforms do you see this crash on?

Feel free to submit a PR if you think a mention is required.

prompteus commented 6 years ago

I use react - CRA + cordova. I have settings whether to keep the screen on, but the settings affects only one particular view, app should allow screen sleep elsewhere. So when the view enters the screen, it checks the settings and conditionally calls keepsAwake accordingly. When the view leaves the screen, it calls allowSleepAgain without checking whether keepAwake was called or not. I expected that nothing would happen if called "pointlessly", same as setting for example a flag on android pointlessly doesn't throw.

I will submit a PR when I get to it.

EddyVerbruggen commented 6 years ago

Exactly, that's what I meant with "the plugin could perhaps harden against 'bad' usage patterns". Happy to merge your PR!

prompteus commented 6 years ago

Thanks. I've just requested it.

EddyVerbruggen commented 6 years ago

Perfect, that'll do for now.