Skip to content

Commit 3cef28e

Browse files
committed
Core devices local timeline api
1 parent 493590f commit 3cef28e

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

lib/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { sendAppMessage } from "./appMessage";
2-
import { getTimelineToken } from "./timeline";
2+
import {
3+
getTimelineToken,
4+
insertTimelinePin,
5+
deleteTimelinePin,
6+
} from "./timeline";
37
import { fetchString, fetchJSON, fetchBinary } from "./fetch";
48

59
export default {
610
sendAppMessage,
711
getTimelineToken,
12+
insertTimelinePin,
13+
deleteTimelinePin,
814
fetchString,
915
fetchJSON,
1016
fetchBinary,

lib/timeline.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,29 @@ export function getTimelineToken(): Promise<string> {
77
Pebble.getTimelineToken(resolve, reject);
88
});
99
}
10+
11+
/**
12+
* Adds a timeline pin to the user's timeline.
13+
* Only works on the Core Devices app. This function will throw when not available.
14+
* @param pin - TimelinePin object or string
15+
* @throws Error if insertTimelinePin is not available
16+
*/
17+
export function insertTimelinePin(pin: TimelinePin | string): void {
18+
if (!Pebble.insertTimelinePin) {
19+
throw new Error("insertTimelinePin is not available");
20+
}
21+
Pebble.insertTimelinePin(pin);
22+
}
23+
24+
/**
25+
* Deletes a pin from the user's timeline by id.
26+
* Only works on the Core Devices app. This function will throw when not available.
27+
* @param id - The ID of the timeline pin to remove
28+
* @throws Error if removeTimelinePin is not available
29+
*/
30+
export function deleteTimelinePin(id: string): void {
31+
if (!Pebble.deleteTimelinePin) {
32+
throw new Error("deleteTimelinePin is not available");
33+
}
34+
Pebble.deleteTimelinePin(id);
35+
}

0 commit comments

Comments
 (0)