Skip to content

useWakeLock

Category
Export Size
618 B
Last Changed
5 days ago

Reactive Screen Wake Lock API. Provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.

Demo

Usage

tsx
import { 
useWakeLock
} from '@reause/core'
const {
isSupported
,
isActive
,
forceRequest
,
request
,
release
} =
useWakeLock
()

When request is called, the wake lock will be requested if the document is visible. Otherwise, the request will be queued until the document becomes visible. If the request is successful, isActive will be true. Whenever the document is hidden, the isActive will be false.

When release is called, the wake lock will be released. If there is a queued request, it will be canceled.

To request a wake lock immediately, even if the document is hidden, use forceRequest. Note that this may throw an error if the document is hidden.

Type Declarations

ts
export type WakeLockType = 'screen'

export interface WakeLockSentinel extends EventTarget {
    type: WakeLockType;
    released: boolean;
    release: () => Promise<void>;
}

export interface UseWakeLockOptions {
    navigator?: Navigator;
    document?: Document;
}

export interface UseWakeLockReturn {
    sentinel: WakeLockSentinel | null;
    isSupported: boolean;
    isActive: boolean;
    request: (type: WakeLockType) => Promise<void>;
    forceRequest: (type: WakeLockType) => Promise<void>;
    release: () => Promise<void>;
}

export function useWakeLock(options?: UseWakeLockOptions): UseWakeLockReturn

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
ddc50 - fix(core): resolve useWakeLock audit findings (#690)

Released under the MIT License. v0.1.8