Skip to content

Instantly share code, notes, and snippets.

@fletchto99 fletchto99/target.c
Created Nov 20, 2016

Embed
What would you like to do?
Pebble App sandbox escape, target application
#include <pebble.h>
static Window *s_window;
static TextLayer *s_text_layer;
static void init(void) {
// Create a window and get information about the window
s_window = window_create();
Layer *window_layer = window_get_root_layer(s_window);
GRect bounds = layer_get_bounds(window_layer);
// Create a text layer and set the text
s_text_layer = text_layer_create(bounds);
int test = persist_read_int(1);
static char buf[] = "0"; /* <-- implicit NUL-terminator at the end here */
snprintf(buf, sizeof(buf), "%d", test);
text_layer_set_text(s_text_layer, buf);
// Set the font and text alignment
text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
// Add the text layer to the window
layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
// Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
// Push the window, setting the window animation to 'true'
window_stack_push(s_window, true);
// App Logging!
APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
}
static void deinit(void) {
// Destroy the text layer
text_layer_destroy(s_text_layer);
// Destroy the window
window_destroy(s_window);
}
int main(void) {
init();
app_event_loop();
deinit();
}
Pebble.addEventListener('ready', function() {
console.log("Hello from the target app");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.