forked from janvarev/Irene-Voice-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
request wake lock on web interface page
- Loading branch information
1 parent
20bc957
commit e194469
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let wakeLock: /*WakeLockSentinel*/ any | null = null; | ||
|
||
async function requestWakeLock() { | ||
try { | ||
// TODO: Видимо, нужно обновить TS, чтобы типы, связанные с WakeLock определялись | ||
const wl = await (window.navigator as any).wakeLock.request("screen"); | ||
if (wakeLock) { | ||
wakeLock.release(); | ||
} | ||
wakeLock = wl; | ||
console.log("WakeLock получен"); | ||
} catch (err) { | ||
console.log("Ошибка при получении WakeLock", err); | ||
} | ||
} | ||
|
||
export function enableWakeLock() { | ||
if (!(window.navigator as any).wakeLock) { | ||
return; | ||
} | ||
|
||
requestWakeLock(); | ||
|
||
document.addEventListener("visibilitychange", () => { | ||
if (document.visibilityState === "visible") { | ||
requestWakeLock(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters