ws4kp/server/scripts/modules/utils/nosleep.mjs

19 lines
539 B
JavaScript
Raw Permalink Normal View History

2022-12-06 22:14:56 +00:00
// track state of nosleep locally to avoid a null case error
// when nosleep.disable is called without first calling .enable
let wakeLock = false;
const noSleep = (enable = false) => {
// get a nosleep controller
if (!noSleep.controller) noSleep.controller = new NoSleep();
// don't call anything if the states match
if (wakeLock === enable) return false;
// store the value
wakeLock = enable;
// call the function
if (enable) return noSleep.controller.enable();
return noSleep.controller.disable();
};
export default noSleep;