Skip to content

Commit

Permalink
Add property "enabled" and method "isEnabled()"
Browse files Browse the repository at this point in the history
Fixes #109.
  • Loading branch information
richtr committed Dec 15, 2020
1 parent 2852d15 commit 0f153f2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
20 changes: 19 additions & 1 deletion dist/NoSleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var NoSleep = function () {

_classCallCheck(this, NoSleep);

this.enabled = false;
if (nativeWakeLock()) {
this._wakeLock = null;
var handleVisibilityChange = function handleVisibilityChange() {
Expand Down Expand Up @@ -181,6 +182,7 @@ var NoSleep = function () {
if (nativeWakeLock()) {
return navigator.wakeLock.request("screen").then(function (wakeLock) {
_this2._wakeLock = wakeLock;
_this2.enabled = true;
console.log("Wake Lock active.");
_this2._wakeLock.addEventListener("release", function () {
// ToDo: Potentially emit an event for the page to observe since
Expand All @@ -189,7 +191,9 @@ var NoSleep = function () {
console.log("Wake Lock released.");
});
}).catch(function (err) {
_this2.enabled = false;
console.error(err.name + ", " + err.message);
throw err;
});
} else if (oldIOS()) {
this.disable();
Expand All @@ -200,9 +204,17 @@ var NoSleep = function () {
window.setTimeout(window.stop, 0);
}
}, 15000);
this.enabled = true;
return Promise.resolve();
} else {
return this.noSleepVideo.play();
var playPromise = this.noSleepVideo.play();
return playPromise.then(function (res) {
_this2.enabled = true;
return res;
}).catch(function (err) {
_this2.enabled = false;
throw err;
});
}
}
}, {
Expand All @@ -222,6 +234,12 @@ var NoSleep = function () {
} else {
this.noSleepVideo.pause();
}
this.enabled = false;
}
}, {
key: "isEnabled",
get: function get() {
return this.enabled;
}
}]);

Expand Down
Loading

0 comments on commit 0f153f2

Please sign in to comment.