Class ScreenWakeLock

java.lang.Object
org.vaadin.firitin.util.ScreenWakeLock

@Deprecated(since="3.6", forRemoval=true) public class ScreenWakeLock extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
Vaadin 25.2 ships a native equivalent, WakeLock. Prefer it: WakeLock.request() / WakeLock.release() plus WakeLock.activeSignal() (a Signal<Boolean> that flips to false automatically when the browser releases the lock) replace the CompletableFuture + release-listener + checkState() combo. WakeLock.availabilitySignal() provides feature detection.
A Vaadin wrapper for the browser's Screen Wake Lock API.

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 Classes
    Modifier and Type
    Class
    Description
    static enum 
    Deprecated, for removal: This API element is subject to removal in a future version.
    Represents the state of the screen wake lock.
  • Method Summary

    Modifier and Type
    Method
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Checks the current state of the screen wake lock for the current UI instance.
    checkState(com.vaadin.flow.component.UI ui)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Checks the current state of the screen wake lock for the specified UI instance.
    static void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Releases the screen wake lock for the current UI instance.
    static void
    release(com.vaadin.flow.component.UI ui)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Releases the screen wake lock for the specified UI instance.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Requests a screen wake lock for the current UI instance without a release callback.
    request(com.vaadin.flow.component.UI ui, Runnable onReleased)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Requests a screen wake lock for the specified UI instance.
    request(Runnable onReleased)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Requests a screen wake lock for the current UI instance with a release callback.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • request

      public static CompletableFuture<ScreenWakeLock.State> request(com.vaadin.flow.component.UI ui, Runnable onReleased)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Requests a screen wake lock for the specified UI instance.

      This method acquires a WakeLockSentinel by calling navigator.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 lock
      onReleased - an optional callback that will be invoked when the wake lock is released (either manually via release(UI) or automatically by the browser). Can be null if no callback is needed.
      Returns:
      a CompletableFuture that completes with the wake lock state. Returns ScreenWakeLock.State.ACTIVE if the lock was successfully acquired, or ScreenWakeLock.State.ERROR if an error occurred (e.g., browser doesn't support the API, permissions denied, or not in a secure context).
      See Also:
    • request

      public static CompletableFuture<ScreenWakeLock.State> request(Runnable onReleased)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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 via release() or automatically by the browser). Can be null if no callback is needed.
      Returns:
      a CompletableFuture that completes with the wake lock state
      See Also:
    • request

      public static CompletableFuture<ScreenWakeLock.State> request()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Releases the screen wake lock for the specified UI instance.

      This method manually releases the wake lock by calling release() on the WakeLockSentinel. Once released, if a new wake lock is needed, a new request must be made via request(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()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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

      public static CompletableFuture<ScreenWakeLock.State> checkState(com.vaadin.flow.component.UI ui)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Checks the current state of the screen wake lock for the specified UI instance.

      This method queries the WakeLockSentinel.released property 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:
      See Also:
    • checkState

      public static CompletionStage<ScreenWakeLock.State> checkState()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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: