Class WakeLock

java.lang.Object
com.vaadin.flow.component.page.WakeLock
All Implemented Interfaces:
Serializable

public final class WakeLock extends Object implements Serializable
Browser Screen Wake Lock API for Flow applications. Keeps the screen from dimming or locking while the lock is held — useful for dashboards, kiosks, presentations, and recipe / workout screens.

Reach the per-UI instance through Page.getWakeLock().

Example:

 WakeLock wakeLock = UI.getCurrent().getPage().getWakeLock();
 wakeLock.request();

 Signal.effect(this, () -> {
     statusLabel.setText(
             wakeLock.activeSignal().get() ? "Screen will stay on" : "Idle");
 });
 

Lifecycle. request() fires the browser request asynchronously and activeSignal() flips to true once the browser confirms. The browser releases the lock automatically when the tab is hidden; the client transparently re-acquires it when the tab becomes visible again, so a single request() is enough for the lifetime of the view. Call release() to stop re-acquiring and drop the current lock.

Reliability caveats.

  • Safari only ships the Screen Wake Lock API from version 16.4.
  • The browser requires a secure context (HTTPS or localhost); on an insecure origin the call fails silently and activeSignal() stays false.
  • Some browsers release the lock on low battery or when the device enters power-saving mode; activeSignal() reflects this immediately.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a read-only signal that reflects whether the browser is currently holding the wake lock on behalf of this UI.
    void
    Releases the screen wake lock and stops re-acquiring it on subsequent visibility changes.
    void
    Asks the browser to acquire a screen wake lock and keep re-acquiring it across tab visibility changes.

    Methods inherited from class java.lang.Object

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

    • request

      public void request()
      Asks the browser to acquire a screen wake lock and keep re-acquiring it across tab visibility changes.

      The call is asynchronous and fire-and-forget: by the time this method returns the browser has not necessarily granted the lock yet. Observe activeSignal() to react to the actual state. Calling request() when a lock is already held is a no-op.

    • release

      public void release()
      Releases the screen wake lock and stops re-acquiring it on subsequent visibility changes. Idempotent — calling it when no lock is held is a no-op.
    • activeSignal

      public Signal<Boolean> activeSignal()
      Returns a read-only signal that reflects whether the browser is currently holding the wake lock on behalf of this UI.

      Starts as false, flips to true when the browser confirms a request, and flips back to false whenever the browser releases the lock — explicitly through release(), automatically when the tab becomes hidden, or because the browser dropped it (power saving, low battery). When the tab is shown again the client re-requests the lock if release() has not been called, so the signal flips back to true shortly after.

      Use Signal.effect(owner, ...) to react to changes and .peek() for a snapshot outside a reactive context.

      Returns:
      the read-only active-state signal