Keep Screen On Plugin Note

name

Keep Screen On

icon

brightness_5

description

Activate to keep your screen from locking for a fixed amount of time.


(() => ({
async appOption(app) {
if (!("wakeLock" in navigator)) {
app.alert("Wake Lock API is not supported by your device");
return;
}
 
const milliseconds = await app.prompt("Keep screen on for how long?", {
inputs: [
{
options: [
{ label: "5 minutes", value: 5 * 60 * 1000 },
{ label: "10 minutes", value: 10 * 60 * 1000 },
],
type: "select",
value: 5 * 60 * 1000
}
]
});
 
if (!Number.isInteger(milliseconds)) {
return;
}
 
while (true) {
let wakeLock = null;
try {
wakeLock = await navigator.wakeLock.request("screen");
} catch (err) {
app.alert("Failed to activate Wake Lock API");
return;
}
 
try {
await new Promise(resolve => setTimeout(resolve, milliseconds));
} finally {
if (wakeLock) await wakeLock.release();
}
 
const alertResult = await app.alert("Done", {
actions: [
{
icon: "restart_alt",
label: "Repeat",
value: "repeat",
}
]
});
 
if (alertResult !== "repeat") {
return;
}
}
}
}))()