Skip to content

Commit

Permalink
Added minor comments to no_sleep.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
diegotori committed Dec 3, 2024
1 parent ac4e069 commit a7ddb22
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wakelock_plus/lib/assets/no_sleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var NoSleep = (function () {
var _this2 = this

if (nativeWakeLock) {
// Disalbe any previously held wakelocks.
await this.disable()
if (_nativeEnabledCompleter == null) {
_nativeEnabledCompleter = new PromiseCompleter()
Expand All @@ -146,6 +147,7 @@ var NoSleep = (function () {
_this2.nativeEnabled = true
_nativeEnabledCompleter.complete()
_nativeEnabledCompleter = null
// We now have a wakelock. Notify all of the existing callers.
console.log("Wake Lock active.");
_this2._wakeLock.addEventListener('release', function () {
_this2.nativeEnabled = false
Expand All @@ -160,6 +162,7 @@ var NoSleep = (function () {
_nativeEnabledCompleter.completeError(errorMessage)
_nativeEnabledCompleter = null
})
// We then wait for screen to be made available.
return _nativeEnabledCompleter.future
} else if (oldIOS) {
this.disable()
Expand Down Expand Up @@ -195,6 +198,7 @@ var NoSleep = (function () {
key: 'disable',
value: async function disable() {
if (nativeWakeLock) {
// If we're still trying to enable the wakelock, wait for it to be enabled
if (_nativeEnabledCompleter != null) {
await _nativeEnabledCompleter.future
}
Expand Down Expand Up @@ -225,6 +229,7 @@ var NoSleep = (function () {
key: 'isEnabled',
value: async function isEnabled() {
if (nativeWakeLock) {
// If we're still trying to enable the wakelock, wait for it to be enabled
if (_nativeEnabledCompleter != null) {
await _nativeEnabledCompleter.future
}
Expand Down

0 comments on commit a7ddb22

Please sign in to comment.