Skip to content

Commit

Permalink
Keep the screen on at all time.
Browse files Browse the repository at this point in the history
Keep th screen on before starting the timer - this is the time we're
waiting for start procedure and we need the app available.
  • Loading branch information
gonzomir committed Jun 7, 2024
1 parent 863ae1a commit ffe3613
Showing 1 changed file with 23 additions and 39 deletions.
62 changes: 23 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
}
var s = new Date();
var starttime = s.getTime()/1000 + t;
await getScreenLock();
cdt = setInterval(function() {
var n = new Date();
var now = n.getTime()/1000;
Expand All @@ -112,7 +111,6 @@
sb.onclick = function() {
startcountdown(300);
};
releaseScreenLock();
return;
}
if (secleft < 5*60) {
Expand Down Expand Up @@ -164,7 +162,6 @@
}
var s = new Date();
var starttime = s.getTime()/1000;
await getScreenLock();
cht = setInterval(function() {
var n = new Date();
var now = n.getTime()/1000;
Expand All @@ -184,36 +181,6 @@
cp = !cp;
}

async function getScreenLock() {
if (!navigator.wakeLock) {
return;
}

try {
sl = await navigator.wakeLock.request();
console.log('Got screen lock.');
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}

function releaseScreenLock() {
if (!navigator.wakeLock || !sl) {
return;
}

sl.release();
console.log('Screen lock releasd.');
}

async function handleVisibilityChange() {
if (sl !== null && document.visibilityState === 'visible') {
await getScreenLock();
}
};

document.addEventListener('visibilitychange', handleVisibilityChange);

sb.onclick = async function() {
await startcountdown(300);
};
Expand All @@ -225,9 +192,6 @@
await startcountdown(300);
};
sb.innerHTML = '5 min';
if ( !cht ) {
releaseScreenLock();
}
};

stb.onclick = async function() {
Expand All @@ -245,12 +209,32 @@
await startchronometer();
};
stb.innerHTML = 'start';
if (!cdt) {
releaseScreenLock();
}
};

};

async function getScreenLock() {
if (!navigator.wakeLock) {
return;
}

try {
sl = await navigator.wakeLock.request();
console.log('Got screen lock.');
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}

async function handleVisibilityChange() {
if (sl !== null && document.visibilityState === 'visible') {
await getScreenLock();
}
};

document.addEventListener('visibilitychange', handleVisibilityChange);

await getScreenLock();
</script>
<style>
* {
Expand Down

0 comments on commit ffe3613

Please sign in to comment.