Pebble.Platform

Platform glue for Pebble watch applications.

This module wraps Platform.worker so your init function receives a typed LaunchContext decoded from JSON launch metadata.

import Pebble.Platform as Platform

init context =
    ( { model
        | launchedByQuickLaunch =
            context.reason == Platform.LaunchQuickLaunch
        , launchButton = context.launchButton
        , screen = context.screen
      }
    , Cmd.none
    )

subscriptions _ =
    Platform.onScreenChange ScreenChanged

Start apps with Platform.application and watchfaces with Platform.watchface.

For runnable examples, use the watch-demo-launch and watch-demo-screen-change project templates in the IDE.

Native Pebble C API

  • App on developer.repebble.com

Launch metadata

LaunchReason

type LaunchReason
    = LaunchSystem
    | LaunchUser
    | LaunchPhone
    | LaunchWakeup
    | LaunchWorker
    | LaunchQuickLaunch
    | LaunchTimelineAction
    | LaunchSmartstrap
    | LaunchUnknown

Why the app or worker launched on the watch.

LaunchScreen

type alias LaunchScreen =
    { width : Int
    , height : Int
    , shape : DisplayShape
    , colorMode : ColorCapability
    }

Screen details for the currently simulated or connected watch model.

LaunchContext

type alias LaunchContext =
    { reason : LaunchReason
    , watchModel : String
    , watchProfileId : String
    , screen : LaunchScreen
    , hasMicrophone : Bool
    , hasCompass : Bool
    , supportsHealth : Bool
    , launchButton : Maybe Button
    , quickLaunchAction : QuickLaunchAction
    }

Full launch metadata delivered to init.

QuickLaunchAction

type QuickLaunchAction
    = QuickLaunchNone
    | QuickLaunchHold
    | QuickLaunchTap
    | QuickLaunchCombo
    | QuickLaunchUnknown

How the user quick-launched the app, when reason is LaunchQuickLaunch.

ColorCapability

type ColorCapability
    = BlackWhite
    | Color

Color capability for the currently simulated or connected watch model.

DisplayShape

type DisplayShape
    = Rectangular
    | Round

Display shape for the currently simulated or connected watch model.

launchReasonFromTag

launchReasonFromTag : Int -> LaunchReason

Decode an integer launch tag into a LaunchReason.

launchReasonToInt

launchReasonToInt : LaunchReason -> Int

Encode a LaunchReason into the integer tag used by the native runtime.

colorCapabilityIsColor

colorCapabilityIsColor : ColorCapability -> Bool

Whether a color capability supports color rendering.

displayShapeIsRound

displayShapeIsRound : DisplayShape -> Bool

Whether a display shape is round.

Screen changes

onScreenChange

onScreenChange : (LaunchScreen -> msg) -> Sub msg

Receive screen dimension or capability changes from the Pebble runtime.

Program entrypoint

watchface

watchface : { init : LaunchContext -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, view : model -> view
, subscriptions : model -> Sub msg
}
-> Program Decode.Value model msg

Start a Pebble watchface.

config.init receives a typed launch context. view is retained as the watch rendering contract, while init/update/subscriptions are forwarded to Elm's headless Platform.worker.

application

application : { init : LaunchContext -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, view : model -> view
, subscriptions : model -> Sub msg
}
-> Program Decode.Value model msg

Start a Pebble watch application.

Use this for apps rather than watchfaces. It currently has the same runtime shape as watchface, but keeps the app/watchface distinction explicit for build tooling.