When I call noSleep.enable() multiple times and then call noSleep.disable() I would expect all existing WakeLocks to be disabled/released.
Actual Behavior / Situation
I have a use case where noSleep.enable() might be called multiple times instead of just once. Reasons:
I trigger it on both click and touchend
I further trigger it based on some application-specific logic (but only after the user has interacted with the page)
Now, as far as I understand the code NoSleep.js will always try to use the native (Chrome) WakeLock if available.
Judging by the behavior of my app and looking at the code I believe that noSleep.enable() is currently not idempotent for the native WakeLock.
In my use case, this meant that when I call noSleep.enable() multiple times then NoSleep would (presumably) create multiple WakeLockSentinel objects.
The problem is that noSleep.disable() just releases the latest WakeLockSentinel and not the older ones.
This means that when I call noSleep.enable() multiple times I will not be able to use noSleep.disable() to actually release (all) the WakeLock(s). This means that the screen will stay wakelocked, even if I don't want it to.
Modification Proposal
Either maintain a reference to all native wakelocks or (probably better) release the older ones before creating the new one or (probably even better) not create a new one if there is already an existing one.
Expected Behavior / Situation
When I call
noSleep.enable()
multiple times and then callnoSleep.disable()
I would expect all existing WakeLocks to be disabled/released.Actual Behavior / Situation
I have a use case where noSleep.enable() might be called multiple times instead of just once. Reasons:
click
andtouchend
Now, as far as I understand the code
NoSleep.js
will always try to use the native (Chrome)WakeLock
if available. Judging by the behavior of my app and looking at the code I believe that noSleep.enable() is currently not idempotent for the nativeWakeLock
.In my use case, this meant that when I call
noSleep.enable()
multiple times thenNoSleep
would (presumably) create multiple WakeLockSentinel objects. The problem is thatnoSleep.disable()
just releases the latestWakeLockSentinel
and not the older ones.This means that when I call
noSleep.enable()
multiple times I will not be able to usenoSleep.disable()
to actually release (all) the WakeLock(s). This means that the screen will stay wakelocked, even if I don't want it to.Modification Proposal
Either maintain a reference to all native wakelocks or (probably better) release the older ones before creating the new one or (probably even better) not create a new one if there is already an existing one.