Pebble.AppFocus
Observe when the watch app gains or loses foreground focus.
Subscribe once and update your model when the user leaves or returns to your app.
import Pebble.AppFocus as AppFocus
type Msg
= FocusChanged AppFocus.State
subscriptions _ =
AppFocus.onChange FocusChanged
update msg model =
case msg of
FocusChanged AppFocus.InFocus ->
( { model | paused = False }, Cmd.none )
FocusChanged AppFocus.OutOfFocus ->
( { model | paused = True }, Cmd.none )
For a runnable example, use the watch-demo-app-focus project template in the IDE.
Native Pebble C API
- AppFocusService on developer.repebble.com
Union Types
State
type State
= InFocus
| OutOfFocusWhether the app is currently in the foreground.
Subscriptions
onChange
onChange : (State -> msg) -> Sub msgReceive focus changes from the Pebble runtime.