Alloy exposes information about the watch and screen through the watch,
screen, and device globals, delivers app lifecycle events through watch,
and lets you control the backlight with watch.light().
Platform Support: These APIs are available on Emery (Pebble Time 2) and Gabbro (Pebble Time 2 round).
The watch global describes the device and the user's preferences:
console.log(`watch.model ${watch.model}`);
console.log(`firmware ${watch.firmwareVersion.major}.${watch.firmwareVersion.minor}.${watch.firmwareVersion.patch}`);
console.log(`user prefers ${watch.hour12 ? "12" : "24"} hour display`);
| Property | Description |
|---|---|
watch.model |
The watch model identifier. |
watch.firmwareVersion |
Object with major, minor, and patch numbers. |
watch.hour12 |
true if the user prefers a 12-hour clock, false for 24-hour. |
watch.launch |
How the app was launched: reason and arguments. |
watch.wake |
Present when launched by a wakeup; see Wakeups. |
The screen global describes the display:
console.log(`screen ${screen.width} x ${screen.height}`);
console.log(`round ${screen.round}, color ${screen.color}`);
| Property | Description |
|---|---|
screen.width |
Display width in pixels. |
screen.height |
Display height in pixels. |
screen.round |
true on round displays (Gabbro). |
screen.color |
true on color displays. |
The device.sensor object reports which sensors are available, so you can
feature-detect before using one:
const hasTouch = device.sensor.Touch ? true : false;
console.log(`touch available ${hasTouch}`);
Subscribe to app events on watch with addEventListener:
watch.addEventListener("willFocus", inFocus => {
console.log(`willFocus with inFocus ${inFocus}`);
});
watch.addEventListener("didFocus", inFocus => {
console.log(`didFocus with inFocus ${inFocus}`);
});
watch.addEventListener("resize", progress => {
console.log(`screen resized to ${screen.width} x ${screen.height} at progress ${progress}`);
});
| Event | Description |
|---|---|
"willFocus" |
The app is about to gain or lose focus. The handler receives inFocus. |
"didFocus" |
The app has gained or lost focus. The handler receives inFocus. |
"resize" |
The drawable area is changing size (for example during an animation). The handler receives the animation progress. |
Use watch.light() to control the backlight:
watch.light(true); // force the backlight on
watch.light(false); // turn the backlight off
watch.light(); // turn on temporarily, as if the user interacted
Calling watch.light() with no argument turns the backlight on for the
standard auto-off interval, just like a button press or shake would. Passing a
boolean forces the backlight on or off.
Note: Holding the backlight on draws significantly more power than letting it auto-off. Only force it on for short, deliberate interactions.
See the
helloinfo,
helloappevents,
and
hellolight
examples for complete projects.