WIP
This commit is contained in:
7
.clang-format
Normal file
7
.clang-format
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
TabWidth: 4
|
||||||
|
IndentWidth: 4
|
||||||
|
UseTab: ForIndentation
|
||||||
|
ColumnLimit: 0
|
||||||
|
...
|
||||||
20
package.json
20
package.json
@@ -9,14 +9,16 @@
|
|||||||
"capabilities": [
|
"capabilities": [
|
||||||
"health"
|
"health"
|
||||||
],
|
],
|
||||||
"name": "one-more-episode",
|
"name": "1-more-episode",
|
||||||
"pebble": {
|
"pebble": {
|
||||||
"displayName": "One More Episode",
|
"displayName": "1 More Episode",
|
||||||
"enableMultiJS": true,
|
"enableMultiJS": false,
|
||||||
"messageKeys": [
|
"messageKeys": [
|
||||||
"APP_READY",
|
"JS_READY",
|
||||||
"SLEEP_TIME",
|
"SLEEP_TIMESTAMP",
|
||||||
"API_FULL_URL"
|
"API_IS_PLEX",
|
||||||
|
"API_KEY",
|
||||||
|
"API_HOST"
|
||||||
],
|
],
|
||||||
"projectType": "native",
|
"projectType": "native",
|
||||||
"resources": {
|
"resources": {
|
||||||
@@ -24,12 +26,8 @@
|
|||||||
},
|
},
|
||||||
"sdkVersion": "3",
|
"sdkVersion": "3",
|
||||||
"targetPlatforms": [
|
"targetPlatforms": [
|
||||||
"basalt",
|
|
||||||
"chalk",
|
"chalk",
|
||||||
"diorite",
|
"emery"
|
||||||
"flint",
|
|
||||||
"emery",
|
|
||||||
"gabbro"
|
|
||||||
],
|
],
|
||||||
"uuid": "3097b48e-552c-4a78-92b2-566b9128640e",
|
"uuid": "3097b48e-552c-4a78-92b2-566b9128640e",
|
||||||
"watchapp": {
|
"watchapp": {
|
||||||
|
|||||||
42
src/c/main.c
42
src/c/main.c
@@ -2,7 +2,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// declare general statics
|
// declare pkjs statics
|
||||||
|
static bool s_js_ready;
|
||||||
|
|
||||||
|
// declare window statics
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static TextLayer *s_sleep_time_header_layer;
|
static TextLayer *s_sleep_time_header_layer;
|
||||||
static TextLayer *s_sleep_time_layer;
|
static TextLayer *s_sleep_time_layer;
|
||||||
@@ -10,25 +13,28 @@ static TextLayer *s_last_episode_header_layer;
|
|||||||
static TextLayer *s_last_episode_layer;
|
static TextLayer *s_last_episode_layer;
|
||||||
static TextLayer *s_pin_notice_layer;
|
static TextLayer *s_pin_notice_layer;
|
||||||
|
|
||||||
static void set_sleep_start_time_text(time_t *start_time) {
|
// declare tracking statics
|
||||||
static char buffer[8];
|
static time_t s_sleep_timestamp;
|
||||||
struct tm *timeinfo = localtime(start_time);
|
|
||||||
strftime(buffer, sizeof(buffer), "%I:%M", timeinfo);
|
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
text_layer_set_text(s_sleep_time_layer, buffer);
|
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_JS_READY);
|
||||||
|
if (ready_tuple) {
|
||||||
|
s_js_ready = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cb_update_sleep_time(HealthActivity activity, time_t start_time,
|
static bool cb_update_sleep_time(HealthActivity activity, time_t start_time, time_t end_time, void *context) {
|
||||||
time_t end_time, void *context) {
|
static char buffer[8];
|
||||||
if (activity == HealthActivitySleep) {
|
struct tm *timeinfo = localtime(&start_time);
|
||||||
set_sleep_start_time_text(&start_time);
|
strftime(buffer, sizeof(buffer), "%I:%M", timeinfo);
|
||||||
|
text_layer_set_text(s_sleep_time_layer, buffer);
|
||||||
|
s_sleep_timestamp = start_time;
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_sleep_time() {
|
static void update_sleep_time() {
|
||||||
time_t end_time = time(NULL); // now
|
time_t end_time = time(NULL); // now
|
||||||
time_t start_time = end_time - (2 * (SECONDS_PER_DAY / 2)); // search up to the past 1.5 days
|
time_t start_time = end_time - (SECONDS_PER_DAY * 1.5); // search up to the past 1.5 days
|
||||||
|
|
||||||
health_service_activities_iterate(HealthActivitySleep, start_time, end_time,
|
health_service_activities_iterate(HealthActivitySleep, start_time, end_time,
|
||||||
HealthIterationDirectionPast,
|
HealthIterationDirectionPast,
|
||||||
@@ -42,8 +48,10 @@ static void s_send_to_pkjs() {
|
|||||||
text_layer_set_text(s_last_episode_layer, "Phone comm failure 1");
|
text_layer_set_text(s_last_episode_layer, "Phone comm failure 1");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dict_write_cstring(out, MESSAGE_KEY_SLEEP_TIME, text_layer_get_text(s_sleep_time_layer));
|
dict_write_cstring(out, MESSAGE_KEY_SLEEP_TIMESTAMP, text_layer_get_text(s_sleep_time_layer));
|
||||||
dict_write_cstring(out, MESSAGE_KEY_API_FULL_URL, "https://test.com/api/endpoint?apikey=42069");
|
dict_write_cstring(out, MESSAGE_KEY_API_IS_PLEX, "");
|
||||||
|
dict_write_cstring(out, MESSAGE_KEY_API_KEY, "");
|
||||||
|
dict_write_cstring(out, MESSAGE_KEY_API_HOST, "");
|
||||||
result = app_message_outbox_send();
|
result = app_message_outbox_send();
|
||||||
if (result != APP_MSG_OK) {
|
if (result != APP_MSG_OK) {
|
||||||
text_layer_set_text(s_last_episode_layer, "Phone comm failure 2");
|
text_layer_set_text(s_last_episode_layer, "Phone comm failure 2");
|
||||||
@@ -79,7 +87,7 @@ static void main_window_load(Window *window) {
|
|||||||
if (health_service_any_activity_accessible(HealthActivitySleep, now - (2 * SECONDS_PER_DAY), now) == HealthServiceAccessibilityMaskAvailable) {
|
if (health_service_any_activity_accessible(HealthActivitySleep, now - (2 * SECONDS_PER_DAY), now) == HealthServiceAccessibilityMaskAvailable) {
|
||||||
update_sleep_time();
|
update_sleep_time();
|
||||||
}
|
}
|
||||||
if (strcmp(text_layer_get_text(s_sleep_time_layer), "N/A (rough night?)") == 0) { // TODO change back to != 0 after debug
|
if (strcmp(text_layer_get_text(s_sleep_time_layer), "N/A (rough night?)") != 0) {
|
||||||
// get last episode using PKJS
|
// get last episode using PKJS
|
||||||
psleep(100); // TODO Implement proper wait for PKJS to respond ready
|
psleep(100); // TODO Implement proper wait for PKJS to respond ready
|
||||||
s_send_to_pkjs();
|
s_send_to_pkjs();
|
||||||
@@ -111,7 +119,7 @@ static void init() {
|
|||||||
window_set_window_handlers(
|
window_set_window_handlers(
|
||||||
s_main_window,
|
s_main_window,
|
||||||
(WindowHandlers){.load = main_window_load, .unload = main_window_unload});
|
(WindowHandlers){.load = main_window_load, .unload = main_window_unload});
|
||||||
app_message_open(4096, 4096);
|
app_message_open(8192, 8192);
|
||||||
window_stack_push(s_main_window, true);
|
window_stack_push(s_main_window, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,37 @@
|
|||||||
Pebble.addEventListener("ready", function (e) {
|
Pebble.addEventListener("ready", function () {
|
||||||
Pebble.sendAppMessage({ APP_READY: true });
|
Pebble.sendAppMessage({ JS_READY: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
Pebble.addEventListener("appmessage", function (dict) {
|
Pebble.addEventListener("appmessage", function (dict) {
|
||||||
if (dict.payload["API_FULL_URL"]) {
|
if (dict.payload["API_HOST"]) {
|
||||||
console.log("Time to harass " + dict.payload["API_FULL_URL"] + " to find what you watched at " + dict.payload["SLEEP_TIME"]);
|
console.log("WOAH BRO");
|
||||||
|
if (dict.payload["API_IS_PLEX"] == true) {
|
||||||
|
callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
|
||||||
|
} else {
|
||||||
|
callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function callAPI(fullURL, isPlex, apiKey) {
|
||||||
|
let data = null;
|
||||||
|
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.withCredentials = true;
|
||||||
|
|
||||||
|
xhr.addEventListener("readystatechange", function () {
|
||||||
|
if (this.readyState === this.DONE) {
|
||||||
|
console.log(this.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.open("GET", fullURL);
|
||||||
|
xhr.setRequestHeader("accept", "application/json");
|
||||||
|
if (isPlex == true) {
|
||||||
|
xhr.setRequestHeader("X-Plex-Token", apiKey);
|
||||||
|
} else {
|
||||||
|
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.send(data);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user