Class ScreenWakeLock
The Screen Wake Lock API prevents devices from dimming or locking the screen when an application needs to keep running and remain visible to the user. This is particularly useful for applications like e-book readers, navigation apps, recipe viewers, presentation software, QR/barcode scanners, or any voice or gesture-controlled applications.
Notes:
- Only active documents can acquire screen wake locks. Previously acquired locks are automatically released when the document becomes inactive (e.g., when the page is hidden or minimized).
 - Applications should listen for visibility changes and reacquire the wake lock when the page becomes visible again if continuous lock is required.
 - The API requires a secure context (HTTPS) and browser support may vary.
 
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the state of the screen wake lock. - 
Method Summary
Modifier and TypeMethodDescriptionstatic CompletionStage<ScreenWakeLock.State> Checks the current state of the screen wake lock for the current UI instance.checkState(com.vaadin.flow.component.UI ui) Checks the current state of the screen wake lock for the specified UI instance.static voidrelease()Releases the screen wake lock for the current UI instance.static voidrelease(com.vaadin.flow.component.UI ui) Releases the screen wake lock for the specified UI instance.request()Requests a screen wake lock for the current UI instance without a release callback.Requests a screen wake lock for the specified UI instance.Requests a screen wake lock for the current UI instance with a release callback. 
- 
Method Details
- 
request
public static CompletableFuture<ScreenWakeLock.State> request(com.vaadin.flow.component.UI ui, Runnable onReleased) Requests a screen wake lock for the specified UI instance.This method acquires a
WakeLockSentinelby callingnavigator.wakeLock.request("screen")in the browser, which prevents the device screen from dimming or locking while the lock is active.Important: If the document becomes inactive (e.g., when the user switches tabs or minimizes the browser), the wake lock is automatically released by the browser. Applications that require continuous wake lock should monitor page visibility changes and reacquire the lock when the page becomes visible again.
- Parameters:
 ui- the Vaadin UI instance for which to request the wake lockonReleased- an optional callback that will be invoked when the wake lock is released (either manually viarelease(UI)or automatically by the browser). Can benullif no callback is needed.- Returns:
 - a CompletableFuture that completes with the wake lock state. Returns 
ScreenWakeLock.State.ACTIVEif the lock was successfully acquired, orScreenWakeLock.State.ERRORif an error occurred (e.g., browser doesn't support the API, permissions denied, or not in a secure context). - See Also:
 
 - 
request
Requests a screen wake lock for the current UI instance with a release callback.This is a convenience method that calls
request(UI, Runnable)with the current UI.- Parameters:
 onReleased- a callback that will be invoked when the wake lock is released (either manually viarelease()or automatically by the browser). Can benullif no callback is needed.- Returns:
 - a CompletableFuture that completes with the wake lock state
 - See Also:
 
 - 
request
Requests a screen wake lock for the current UI instance without a release callback.This is a convenience method that calls
request(UI, Runnable)with the current UI and no release callback.- Returns:
 - a CompletableFuture that completes with the wake lock state
 - See Also:
 
 - 
release
public static void release(com.vaadin.flow.component.UI ui) Releases the screen wake lock for the specified UI instance.This method manually releases the wake lock by calling
release()on theWakeLockSentinel. Once released, if a new wake lock is needed, a new request must be made viarequest(UI, Runnable).If no wake lock is currently active, this method has no effect.
- Parameters:
 ui- the Vaadin UI instance for which to release the wake lock- See Also:
 
 - 
release
public static void release()Releases the screen wake lock for the current UI instance.This is a convenience method that calls
release(UI)with the current UI.- See Also:
 
 - 
checkState
Checks the current state of the screen wake lock for the specified UI instance.This method queries the
WakeLockSentinel.releasedproperty to determine the current state of the wake lock. Note that this only checks the state of the wake lock that was requested through this wrapper class.- Parameters:
 ui- the Vaadin UI instance for which to check the wake lock state- Returns:
 - a CompletableFuture that completes with one of the following states:
        
ScreenWakeLock.State.UNKNOWN- No wake lock has been requested yetScreenWakeLock.State.ACTIVE- The wake lock is currently activeScreenWakeLock.State.RELEASED- The wake lock has been released
 - See Also:
 
 - 
checkState
Checks the current state of the screen wake lock for the current UI instance.This is a convenience method that calls
checkState(UI)with the current UI.- Returns:
 - a CompletionStage that completes with the wake lock state
 - See Also:
 
 
 -