mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Wakelock attempt
This commit is contained in:
parent
5635baba28
commit
5fa0783df4
2 changed files with 42 additions and 12 deletions
|
|
@ -108,14 +108,43 @@
|
|||
let wakeLock;
|
||||
const getWakeLock = async () => {
|
||||
try {
|
||||
wakeLock = await navigator.wakeLock.request();
|
||||
wakeLock.addEventListener('release', () => {});
|
||||
console.log('Keeping Screen Awake:', !wakeLock.released);
|
||||
if (navigator.wakeLock) {
|
||||
wakeLock = await navigator.wakeLock.request();
|
||||
wakeLock.addEventListener('release', () => {});
|
||||
console.log('Keeping Screen Awake:', !wakeLock.released);
|
||||
} else {
|
||||
// keepAwake();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`${err.name}, ${err.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
function keepAwake() {
|
||||
let ctx = new AudioContext();
|
||||
|
||||
let bufferSize = 2 * ctx.sampleRate,
|
||||
emptyBuffer = ctx.createBuffer(1, bufferSize, ctx.sampleRate),
|
||||
output = emptyBuffer.getChannelData(0);
|
||||
|
||||
for(let i = 0; i < bufferSize; i++) output[i] = 0;
|
||||
|
||||
let source = ctx.createBufferSource();
|
||||
source.buffer = emptyBuffer;
|
||||
source.loop = true;
|
||||
|
||||
let node = ctx.createMediaStreamDestination();
|
||||
source.connect(node);
|
||||
|
||||
let audio = document.createElement("audio");
|
||||
audio.style.display = "none";
|
||||
document.body.appendChild(audio);
|
||||
|
||||
audio.srcObject = node.stream;
|
||||
audio.play();
|
||||
}
|
||||
|
||||
|
||||
const handleVisibilityChange = async () => {
|
||||
if (wakeLock !== null && document.visibilityState === 'visible') {
|
||||
await getWakeLock();
|
||||
|
|
|
|||
|
|
@ -532,7 +532,7 @@ function render() {
|
|||
// thumbnail.style.transform = `scale(1.1)`;
|
||||
setTimeout(() => thumbnail.style.opacity = 1.0, 0);
|
||||
if (window.scrollY == 0) setTimeout(() => {
|
||||
const yOffset = -10;
|
||||
const yOffset = -20;
|
||||
const element = document.querySelector('.recipe-content');
|
||||
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
||||
window.scrollTo({top: y, behavior: 'smooth'});
|
||||
|
|
@ -554,7 +554,7 @@ function render() {
|
|||
),
|
||||
m(".headerflex",
|
||||
m(".headerleft",
|
||||
m("h1", title),
|
||||
m("h1", {onclick:keepAwake}, title),
|
||||
m(".metadata",
|
||||
(recipeYield) ? m("div", m("span.yield", m(".icon.servings", {innerHTML:icons.servings}), recipeYield)) : null,
|
||||
json.totalTime ? m(".time",
|
||||
|
|
@ -610,14 +610,9 @@ function render() {
|
|||
)
|
||||
}
|
||||
|
||||
var path = window.script.substring(0, window.script.lastIndexOf("."));
|
||||
var cssURL = path + ".css";
|
||||
loadSyle(cssURL).then(render);
|
||||
|
||||
|
||||
|
||||
function keepAwake() {
|
||||
let ctx = null;
|
||||
let ctx = new AudioContext();
|
||||
|
||||
let bufferSize = 2 * ctx.sampleRate,
|
||||
emptyBuffer = ctx.createBuffer(1, bufferSize, ctx.sampleRate),
|
||||
output = emptyBuffer.getChannelData(0);
|
||||
|
|
@ -637,4 +632,10 @@ function keepAwake() {
|
|||
|
||||
audio.srcObject = node.stream;
|
||||
audio.play();
|
||||
console.log("playing", audio)
|
||||
}
|
||||
|
||||
|
||||
var path = window.script.substring(0, window.script.lastIndexOf("."));
|
||||
var cssURL = path + ".css";
|
||||
loadSyle(cssURL).then(render);
|
||||
Loading…
Reference in a new issue