add wakeLock for recipes

This commit is contained in:
Nicholas Jitkoff 2022-06-20 06:58:13 -07:00
parent cfb48615fb
commit aa160c4914
2 changed files with 26 additions and 5 deletions

View file

@ -90,8 +90,26 @@
document.body.classList.remove("copied");
}, 2000);
}
let wakeLock;
const getWakeLock = async () => {
try {
wakeLock = await navigator.wakeLock.request();
wakeLock.addEventListener('release', () => {});
console.log('Keeping Screen Awake:', !wakeLock.released);
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
};
const handleVisibilityChange = async () => {
if (wakeLock !== null && document.visibilityState === 'visible') {
await getWakeLock();
}
};
document.addEventListener('visibilitychange', handleVisibilityChange);
window.addEventListener("message", function(e) {
console.debug("Message:", e.origin, e.data)
@ -109,6 +127,9 @@
if (e.data.share) {
share(e.data.share);
}
if (e.data.wakeLock) {
getWakeLock();
}
if (e.data.replaceURL) {
if (e.data.compressURL) {
let durl = new bitty.DataURL(e.data.replaceURL);
@ -188,9 +209,9 @@
if (info.mediatype == "text/html") {
dataPrefix = HEAD_TAGS();
} else if (info.mediatype == "text/plain") {
//dataPrefix = HEAD_TAGS_EXTENDED();
//fragment = fragment.replace("text/plain", "text/html");
} else if (info.mediatype == "text/plain" || info.mediatype == undefined) {
dataPrefix = HEAD_TAGS_EXTENDED();
fragment = fragment.replace("text/plain", "text/html");
renderMode = "data";
} else if (info.type == "text") {
} else if (info.type == "image") {

View file

@ -190,7 +190,7 @@ function render() {
image = image?.url || image;
instructions = json.recipeInstructions;
let title = clean(json.name);
parent.postMessage({title:title, favicon:"🍴", image:image, updateURL:true}, "*");
parent.postMessage({title:title, favicon:"🍴", image:image, wakeLock:true, updateURL:true}, "*");
// let text = instructions.join(" ");