Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Prevent suspend during presentation w/ Screen Wake Lock API (crosspost) #5

Open
batonac opened this issue Mar 26, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@batonac
Copy link

batonac commented Mar 26, 2024

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.

@batonac batonac added the bug Something isn't working label Mar 26, 2024
@batonac
Copy link
Author

batonac commented Mar 26, 2024

This is a cross post from my original post here: MSzturc/obsidian-advanced-slides#296

@ebullient thanks for keeping this software alive!

@ebullient
Copy link
Owner

Try a PR? Looks like you're pretty close. Feels like this should go in the reveal.html template (rather than embed?) .. I did add a function in there to detect iframe usage for other reasons..

@batonac
Copy link
Author

batonac commented May 5, 2024

I haven't been able to get this working in local dev yet 🤔

@ebullient
Copy link
Owner

No hurry. It isn't something I use, so I'd rather you get it working so it works for you, and then we'll figure out how to make sure it ages well. ;)

@ebullient ebullient added enhancement New feature or request and removed bug Something isn't working labels May 5, 2024
@ebullient ebullient changed the title feat: Prevent suspend during presentation w/ Screen Wake Lock API (crosspost) ✨ Prevent suspend during presentation w/ Screen Wake Lock API (crosspost) May 5, 2024
@ebullient
Copy link
Owner

Just bumping this to remind you that I'm waiting for you. ;)

@batonac
Copy link
Author

batonac commented Aug 10, 2024

Yes, sorry. I'm buried with other things at the moment, but hoping to return to this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants