One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Keep Awake

Keep an app's display from dimming automatically while it is active

One.KeepAwake controls the iOS app’s idle timer and the Android window’s keep-screen-on flag. Set it when a screen needs to remain visible, then clear it when that work ends.

import { One } from 'one'
await One.KeepAwake.setEnabled(true)
const enabled = await One.KeepAwake.isEnabled() // true
await One.KeepAwake.setEnabled(false)

setEnabled and isEnabled use the same app-wide UIApplication.isIdleTimerDisabled flag. The setting affects every route in the current app process; there are no per-screen claims or reference counts. The caller that enables it must disable it when finished. Both methods run on the iOS main thread, and isEnabled reads the current native value. setEnabled accepts only a boolean and does not coerce other values.

The flag does not prevent a person from locking the device, keep the app running in the background, override all iOS power policy, or change screen brightness. iOS Simulator proves the native flag changes, while physical-device auto-lock behavior remains a device proof. The value returns to the system default when the app process ends.

KeepAwake is implemented on iOS and Android. On Android the desired state is held in memory, applied to the foreground window, and re-applied when the activity resumes, so recreation never drops it. SSR validates arguments, setEnabled() does nothing, and isEnabled() resolves false. Web uses the Screen Wake Lock API. setEnabled(true) waits for the actual screen lock; absent support, permission refusal, or a hidden document rejects. setEnabled(false) releases it. isEnabled() reads the current sentinel, so browser release makes it false. A lock is not reacquired automatically when the page becomes visible.

Edit this page on GitHub.