Pebble.Companion.Preferences

Typed declarations for Pebble companion preference pages.

The same schema describes the generated, Slate-like configuration page and the decoder used when Pebble returns saved values.

type alias Settings =
    { showDate : Bool
    , units : Units
    }

type Units
    = Celsius
    | Fahrenheit

settings : Schema Settings
settings =
    schema "Settings" Settings
        |> section "Display"
            (\s ->
                s
                    |> field "showDate" (toggle "Show date" True)
                    |> field "units"
                        (choice "Units"
                            [ choiceOption Celsius "c" "Celsius"
                            , choiceOption Fahrenheit "f" "Fahrenheit"
                            ]
                        )
            )

Native Pebble C API

Schemas

Schema

type Schema settings

Opaque preference schema that decodes to settings.

Error

type Error
    = InvalidJson String
    | MissingResponse

Decode errors from a saved configuration payload.

schema

schema : String -> settings -> Schema settings

Start a schema with a record or custom type constructor.

section

section : String -> (Schema partial -> Schema next) -> Schema partial -> Schema next

Add a visual section. Fields added inside the callback are grouped under the section title.

field

field : String -> Control value -> Schema (value -> next) -> Schema next

Add a typed field to the schema.

Fields are decoded in the order they are added, so this works naturally with Elm record constructors and normal pipeline style.

decoder

decoder : Schema settings -> Decoder settings

Decode the saved Pebble webview payload.

decodeString

decodeString : Schema settings -> String -> Result Error settings

Decode a saved JSON string into typed settings.

decodeResponse

decodeResponse : Schema settings -> Maybe String -> Result Error settings

Decode Pebble's optional webviewclosed response into typed settings.

Controls

Control

type Control value

A typed control for a single field.

Field

type Field value

A typed field. The generator uses the definition; Elm code uses the decoder.

Section

type alias Section =
    { title : String
    , fields : List FieldDefinition
    }

A visual group of fields.

toggle

toggle : String -> Bool -> Control Bool

A boolean toggle.

text

text : String -> String -> Control String

A text input.

number

number : String -> Float -> Control Float

A numeric input.

slider

slider : String -> { min : Float, max : Float, step : Float, default : Float } -> Control Float

A slider with minimum, maximum, step, and default values.

color

color : String -> Color -> Control Color

A color picker encoded as a CSS hex string.

choice

choice : String -> List (ChoiceOption value) -> Control value

A select/radio-style choice that decodes to real Elm values.

ChoiceOption

type ChoiceOption value

A choice option mapping an encoded webview value to a real Elm value.

choiceOption

choiceOption : value -> String -> String -> ChoiceOption value

Define one encoded choice value and the Elm value it represents.

sendToWatch

sendToWatch : String -> Control value -> Control value

Declare the phone-to-watch message constructor emitted when this preference is saved.

This is debugger/build metadata; the typed decoder still determines the Elm value seen by the companion app.

Colors

Color

type alias Color = String

Pebble configuration color value encoded as a CSS hex string.

black

black : Color

Black color swatch.

white

white : Color

White color swatch.

green

green : Color

Green color swatch.

blue

blue : Color

Blue color swatch.

yellow

yellow : Color

Yellow color swatch.