mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-06 00:57:21 -04:00
[WIP] - Allow developers to specify if they want clay to open app message inbox automatically
This commit is contained in:
@@ -59,7 +59,8 @@ static void prv_init(void) {
|
|||||||
.settings_updated = prv_clay_updated_handler,
|
.settings_updated = prv_clay_updated_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
clay_init(CLAY_INBOX_SIZE, &clay_callbacks, NULL);
|
clay_register_callbacks(&clay_callbacks, NULL);
|
||||||
|
clay_init(CLAY_INBOX_SIZE, true);
|
||||||
|
|
||||||
s_window = window_create();
|
s_window = window_create();
|
||||||
window_set_window_handlers(s_window, (WindowHandlers) {
|
window_set_window_handlers(s_window, (WindowHandlers) {
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,9 @@ typedef struct ClayCallbacks {
|
|||||||
ClayUpdatedCallback settings_updated;
|
ClayUpdatedCallback settings_updated;
|
||||||
} ClayCallbacks;
|
} ClayCallbacks;
|
||||||
|
|
||||||
void clay_init(uint32_t inbox_size, const ClayCallbacks *callbacks, void *context);
|
void clay_init(uint32_t inbox_size, bool open_app_message);
|
||||||
|
|
||||||
|
void clay_register_callbacks(const ClayCallbacks *callbacks, void *context);
|
||||||
|
|
||||||
void clay_remove(const char *key);
|
void clay_remove(const char *key);
|
||||||
|
|
||||||
|
|||||||
+25
-17
@@ -9,9 +9,16 @@ static uint32_t prv_hash_key(const char *key) {
|
|||||||
return hash((uint8_t *)key, strlen(key));
|
return hash((uint8_t *)key, strlen(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool prv_read(const char *key, void *value_out, size_t size) {
|
||||||
|
uint32_t persist_key = prv_hash_key(key);
|
||||||
|
int bytes_read = persist_read_data(persist_key, value_out, size);
|
||||||
|
return bytes_read >= 0 && (size_t)bytes_read == size;
|
||||||
|
}
|
||||||
|
|
||||||
static bool prv_write(const char *key, const SimpleDictDataType type, const void *data, size_t size, void *context) {
|
static bool prv_write(const char *key, const SimpleDictDataType type, const void *data, size_t size, void *context) {
|
||||||
uint32_t persist_key = prv_hash_key(key);
|
uint32_t persist_key = prv_hash_key(key);
|
||||||
return persist_write_data(persist_key, data, size) == size;
|
int bytes_written = persist_write_data(persist_key, data, size);
|
||||||
|
return bytes_written >= 0 && (size_t)bytes_written == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) {
|
static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) {
|
||||||
@@ -24,14 +31,24 @@ static void prv_simple_app_message_received_callback(const SimpleDict *message,
|
|||||||
s_callbacks.settings_updated(context);
|
s_callbacks.settings_updated(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool prv_read(const char *key, void *value_out, size_t size) {
|
|
||||||
uint32_t persist_key = prv_hash_key(key);
|
|
||||||
return persist_read_data(persist_key, value_out, size) == size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----- PUBLIC API -----
|
// ----- PUBLIC API -----
|
||||||
|
|
||||||
void clay_init(uint32_t inbox_size, const ClayCallbacks *callbacks, void *context) {
|
void clay_init(uint32_t inbox_size, bool open_app_message) {
|
||||||
|
const bool request_inbox_size_success = simple_app_message_request_inbox_size(inbox_size);
|
||||||
|
if (!request_inbox_size_success) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to request inbox size of %d", (int)inbox_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!open_app_message) return;
|
||||||
|
|
||||||
|
const AppMessageResult open_state = simple_app_message_open();
|
||||||
|
if (open_state != APP_MSG_OK) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to open appmessage inbox. Code: %d", open_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clay_register_callbacks(const ClayCallbacks *callbacks, void *context) {
|
||||||
s_callbacks = *callbacks;
|
s_callbacks = *callbacks;
|
||||||
|
|
||||||
const SimpleAppMessageCallbacks simple_app_message_callbacks = {
|
const SimpleAppMessageCallbacks simple_app_message_callbacks = {
|
||||||
@@ -41,17 +58,8 @@ void clay_init(uint32_t inbox_size, const ClayCallbacks *callbacks, void *contex
|
|||||||
SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context);
|
SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context);
|
||||||
|
|
||||||
if (!register_success) {
|
if (!register_success) {
|
||||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to register callbacks for namespace %s", SIMPLE_APP_MESSAGE_NAMESPACE);
|
APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to register callbacks for namespace %s", SIMPLE_APP_MESSAGE_NAMESPACE);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool request_inbox_size_success = simple_app_message_request_inbox_size(inbox_size);
|
|
||||||
if (!request_inbox_size_success) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to request inbox size of %d", (int)inbox_size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
simple_app_message_open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clay_get_int(const char *key, int *value_out) {
|
bool clay_get_int(const char *key, int *value_out) {
|
||||||
|
|||||||
Reference in New Issue
Block a user