obsidian-slides-extended
obsidian-slides-extended copied to clipboard
✨ Prevent suspend during presentation w/ Screen Wake Lock API (crosspost)
Currently the screen can turn off and the computer suspend during a Advanced Slides presentation, which is problematic. The computer can be set to disable suspend, but that's a cumbersome solution.
It seems easy enough to utilize the Screen Wake Lock API to prevent suspend while the presentation is active:
// Create a reference for the Wake Lock.
let wakeLock = null;
// create an async function to request a wake lock
try {
wakeLock = await navigator.wakeLock.request("screen");
statusElem.textContent = "Wake Lock is active!";
} catch (err) {
// The Wake Lock request has failed - usually system related, such as battery.
statusElem.textContent = `${err.name}, ${err.message}`;
}
Secure context is required, but apparently localhost qualifies:
Locally-delivered resources such as those with http://127.0.0.1 URLs, http://localhost and http://*.localhost URLs (e.g. http://dev.whatever.localhost/), and file:// URLs are also considered to have been delivered securely.
I'm not sure of the best way to differentiate slide "preview" from "presentation mode". The easiest way would be to ensure that the Wake Lock isn't active unless the slides are viewed in an external browser. A more sophisticated approach would be request a wake lock only when the browser window enters full screen mode, and release it when exiting full screen mode.