|
@@ -0,0 +1,31 @@
|
|
|
|
|
+let sentinel = null;
|
|
|
|
|
+
|
|
|
|
|
+export async function enableRecipeMode(){
|
|
|
|
|
+ if(typeof navigator === "undefined" || !("wakeLock" in navigator)) return false;
|
|
|
|
|
+
|
|
|
|
|
+ try{
|
|
|
|
|
+ sentinel = await navigator.wakeLock.request("screen");
|
|
|
|
|
+ sentinel.addEventListener("release", ()=>{sentinel = null});
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }catch{
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function disableRecipeMode(){
|
|
|
|
|
+ await sentinel?.release();
|
|
|
|
|
+ sentinel = null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export function attachVisibilityReacquire(enabled){
|
|
|
|
|
+ if(typeof document === "undefined") return () => {};
|
|
|
|
|
+
|
|
|
|
|
+ async function onVis(){
|
|
|
|
|
+ const isEnabled = typeof enabled === "function" ? enabled() : enabled;
|
|
|
|
|
+ if(document.visibilityState === "visible" && isEnabled){
|
|
|
|
|
+ await enableRecipeMode();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ document.addEventListener("visibilitychange", onVis);
|
|
|
|
|
+ return () => document.removeEventListener("visibilitychange", onVis);
|
|
|
|
|
+}
|