richtr / NoSleep.js

Prevent display sleep and enable wake lock in any Android or iOS web browser.
MIT License
2.23k stars 380 forks source link

fix `nativeWakeLock` code to be consistent with other methods #111

Closed beauxq closed 3 years ago

beauxq commented 3 years ago

Using nativeWakeLock, calling disable when it's not enabled results in thrown exception. Cannot read property 'release' of null

The other 2 methods (oldIOS and the video method) don't throw exception calling disable when it's not enabled.

This change makes it so all 3 methods do nothing if disable is called while already disabled.

Note the documentation for HTMLMediaElement.pause()

if the media is already in a paused state this method will have no effect

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause

This PR contains a:

Motivation / Use-Case

inconsistent behavior between the different ways of preventing sleep

Breaking Changes

If someone was relying on this inconsistency for some reason...

Additional Info

richtr commented 3 years ago

Fixed by 7aa6c05928d3be452444d569b6fa4422d08deb50!