Skip to content

Commit e6cd761

Browse files
author
Sam Wright
committed
removed DS_Store
0 parents  commit e6cd761

13 files changed

+1348
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Ignore build generated files
3+
build
4+
.DS_Store

.lock-waf_darwin_build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
argv = ['/Users/eatmuchpie/Documents/pebble-dev/PebbleSDK-2.0-BETA7/Pebble/waf', 'configure', 'build']
2+
environ = {'TERM_SESSION_ID': '01EFF10F-9FB3-4A19-8249-6EF9B194B0C0', 'SSH_AUTH_SOCK': '/tmp/launch-KUcHqf/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '326', 'Apple_PubSub_Socket_Render': '/tmp/launch-pRHYeA/Render', 'LOGNAME': 'eatmuchpie', 'USER': 'eatmuchpie', 'HOME': '/Users/eatmuchpie', 'PATH': '/Users/eatmuchpie/Documents/pebble-dev/PebbleSDK-2.0-BETA7/arm-cs-tools/bin:/Users/eatmuchpie/Documents/pebble-dev/PebbleSDK-2.0-BETA7/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/go/bin:/Users/eatmuchpie/Downloads/adt-bundle-mac-x86_64-20131030/sdk/tools:/Users/eatmuchpie/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools', 'DISPLAY': '/tmp/launch-5oZg2R/org.macosforge.xquartz:0', 'TMPDIR': '/var/folders/dj/1mxpqprd54d53k3q_w8w5_m00000gn/T/', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_GB.UTF-8', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'VERSIONER_PYTHON_VERSION': '2.7', 'SHLVL': '2', 'ANDROID_HOME': '/Users/eatmuchpie/Downloads/adt-bundle-mac-x86_64-20131030/sdk', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'JAVA_HOME': '/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home', 'PWD': '/Users/eatmuchpie/Documents/pebble-dev/feedly-pebble', '_': '/Users/eatmuchpie/Documents/pebble-dev/PebbleSDK-2.0-BETA7/Pebble/waf', 'GPG_AGENT_INFO': '/Users/eatmuchpie/.gnupg/S.gpg-agent:10944:1', '__CHECKFIX1436934': '1'}
3+
files = ['/Users/eatmuchpie/Documents/pebble-dev/feedly-pebble/wscript']
4+
hash = 4672844372416070989
5+
options = {'files': '', 'jobs': 4, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'timestamp': None, 'distcheck_args': None, 'top': '', 'destdir': '', 'keep': 0, 'zones': '', 'debug': False, 'prefix': '/usr/local/', 'download': False, 'force': False, 'targets': '', 'out': ''}
6+
out_dir = '/Users/eatmuchpie/Documents/pebble-dev/feedly-pebble/build'
7+
run_dir = '/Users/eatmuchpie/Documents/pebble-dev/feedly-pebble'
8+
top_dir = '/Users/eatmuchpie/Documents/pebble-dev/feedly-pebble'

appinfo.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"uuid": "9eadaf2b-ebbc-4b31-ac74-1040245cb7c1",
3+
"shortName": "feedly-pebble",
4+
"longName": "Feedly Pebble App",
5+
"capabilities": [ "configurable" ],
6+
"companyName": "Sam Wright",
7+
"versionCode": 1,
8+
"versionLabel": "1.0.0",
9+
"watchapp": {
10+
"watchface": false
11+
},
12+
"appKeys": {
13+
"operation": 0
14+
},
15+
"resources": {
16+
"media": []
17+
}
18+
}

configuration.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../feedly-pebble-gApp/pebble-feedly/configuration.html

src/comms.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <pebble.h>
2+
#include "comms.h"
3+
4+
5+
6+
void comm_deinit() {
7+
app_message_deregister_callbacks();
8+
}
9+
10+
static void comm_in_received_handler(DictionaryIterator *iter, void *context) {
11+
APP_LOG(APP_LOG_LEVEL_DEBUG, "comm_in_received");
12+
}
13+
14+
static void comm_in_dropped_handler(AppMessageResult reason, void *context) {
15+
APP_LOG(APP_LOG_LEVEL_DEBUG, "comm_in_dropped for reason: %s", translate_error(reason));
16+
}
17+
18+
static void comm_out_sent_handler(DictionaryIterator *sent, void *context) {
19+
APP_LOG(APP_LOG_LEVEL_DEBUG, "comm_out_sent");
20+
}
21+
22+
static void comm_out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) {
23+
APP_LOG(APP_LOG_LEVEL_DEBUG, "comm_out_failed for reason: %s", translate_error(reason));
24+
}
25+
26+
void comm_init() {
27+
app_message_register_inbox_received(comm_in_received_handler);
28+
app_message_register_inbox_dropped(comm_in_dropped_handler);
29+
app_message_register_outbox_sent(comm_out_sent_handler);
30+
app_message_register_outbox_failed(comm_out_failed_handler);
31+
32+
const int inbound_size = app_message_inbox_size_maximum();
33+
const int outbound_size = APP_MESSAGE_OUTBOX_SIZE_MINIMUM;
34+
app_message_open(inbound_size, outbound_size);
35+
36+
app_message_open(inbound_size, outbound_size); // We only need large buffer for inbox
37+
}
38+
39+
char *translate_error(AppMessageResult result) {
40+
switch (result) {
41+
case APP_MSG_OK: return "APP_MSG_OK";
42+
case APP_MSG_SEND_TIMEOUT: return "APP_MSG_SEND_TIMEOUT";
43+
case APP_MSG_SEND_REJECTED: return "APP_MSG_SEND_REJECTED";
44+
case APP_MSG_NOT_CONNECTED: return "APP_MSG_NOT_CONNECTED";
45+
case APP_MSG_APP_NOT_RUNNING: return "APP_MSG_APP_NOT_RUNNING";
46+
case APP_MSG_INVALID_ARGS: return "APP_MSG_INVALID_ARGS";
47+
case APP_MSG_BUSY: return "APP_MSG_BUSY";
48+
case APP_MSG_BUFFER_OVERFLOW: return "APP_MSG_BUFFER_OVERFLOW";
49+
case APP_MSG_ALREADY_RELEASED: return "APP_MSG_ALREADY_RELEASED";
50+
case APP_MSG_CALLBACK_ALREADY_REGISTERED: return "APP_MSG_CALLBACK_ALREADY_REGISTERED";
51+
case APP_MSG_CALLBACK_NOT_REGISTERED: return "APP_MSG_CALLBACK_NOT_REGISTERED";
52+
case APP_MSG_OUT_OF_MEMORY: return "APP_MSG_OUT_OF_MEMORY";
53+
case APP_MSG_CLOSED: return "APP_MSG_CLOSED";
54+
case APP_MSG_INTERNAL_ERROR: return "APP_MSG_INTERNAL_ERROR";
55+
default: return "UNKNOWN ERROR";
56+
}
57+
}

src/comms.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void comm_init();
2+
3+
void comm_deinit();
4+
5+
char *translate_error(AppMessageResult result);

src/feedly-pebble.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <pebble.h>
2+
#include "comms.h"
3+
4+
/*
5+
Communication Dictionary:
6+
7+
in general:
8+
Data_Indices = [12, 20, 32] (i.e. indices of the ends of each data segment)
9+
Data_Stream = "Ars TechnicaPhoronixThe Guardian "
10+
11+
12+
*/
13+
14+
15+
static void init(void) {
16+
window = window_create();
17+
window_set_click_config_provider(window, click_config_provider);
18+
window_set_window_handlers(window, (WindowHandlers) {
19+
.load = window_load,
20+
.unload = window_unload,
21+
});
22+
23+
comm_init();
24+
25+
const bool animated = true;
26+
window_stack_push(window, animated);
27+
}
28+
29+
static void deinit(void) {
30+
window_destroy(window);
31+
comm_deinit();
32+
}
33+
34+
int main(void) {
35+
init();
36+
37+
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", window);
38+
39+
app_event_loop();
40+
deinit();
41+
}
42+

src/js/JSONRequester.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
function JSONRequester(requestType, url, params, onload, onerror=null) {
3+
4+
// === Constructor ===
5+
6+
var request;
7+
var attempts_left = 2;
8+
var using_auth;
9+
var that = this;
10+
11+
if (params) {
12+
var key_value_pairs = [];
13+
for (var key in params) {
14+
var value = params[key];
15+
key_value_pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
16+
}
17+
url += "?" + key_value_pairs.join("&");
18+
}
19+
20+
createRequest();
21+
22+
// ==== Private Methods ===
23+
24+
function createRequest() {
25+
request = new XMLHttpRequest();
26+
request.open(requestType, url, true);
27+
request.setRequestHeader("Content-Type", "application/json");
28+
29+
request.onload = function(e) {
30+
onload(JSON.parse(request.responseText));
31+
}
32+
33+
request.onerror = function(e) {
34+
if (request.status == 401 && using_auth && attempts_left > 0) {
35+
attempts_left--;
36+
console.log("Access token was bad - removing it. " + );
37+
window.localStorage.removeItem("access_token");
38+
createRequest();
39+
sendAuthenticated();
40+
} else {
41+
if (onerror)
42+
onerror(e);
43+
else
44+
console.log("Error: " + e);
45+
}
46+
}
47+
}
48+
49+
// ==== Privileged Methods ====
50+
51+
// Send without authentication
52+
this.send = function() {
53+
using_auth = false;
54+
request.send(null);
55+
}
56+
57+
// Send with authentication
58+
this.sendAuthenticated = function() {
59+
using_auth = true;
60+
61+
// Check if access token exists and is valid:
62+
var access_token = window.localStorage.getItem("access_token");
63+
console.log("injectAccessToken called... access token is: " + access_token);
64+
if (access_token) {
65+
request.setRequestHeader("Authorization", "OAuth " + access_token);
66+
console.log("injecting access_token!");
67+
return request.send(null);
68+
}
69+
70+
// Access token didn't exist, so get new one from refresh token
71+
var refresh_token = window.localStorage.getItem("refresh_token");
72+
console.log("access token was null. Refresh token is: " + refresh_token);
73+
if (refresh_token) {
74+
console.log("using refresh token to get new access token");
75+
76+
// refresh token exists - try to generate new access token from it
77+
new JSONRequester("GET", feedly_url + "/v3/auth/token",
78+
{
79+
"refresh_token": refresh_token,
80+
"client_id": client_id,
81+
"client_secret": client_secret,
82+
"grant_type": "refresh_token"
83+
},
84+
function(e) { // onload
85+
// Save new access token:
86+
window.localStorage.setItem("access_token", value.access_token);
87+
console.log("Got new access token from refresh token");
88+
// Use access token in recursive call:
89+
return that.sendAuthenticated();
90+
},
91+
function(e) { // onerror
92+
// Refresh token was invalid. Delete it and try getting new one from oauth_token
93+
console.log("Refresh token was invalid. Will attempt getting new one...");
94+
window.localStorage.removeItem("refresh_token");
95+
return that.sendAuthenticated();
96+
}
97+
).send();
98+
99+
return;
100+
}
101+
102+
// Both access and refresh tokens are undefined. Generate new ones from oauth_token
103+
var oauth_token = window.localStorage.getItem("oauth_token");
104+
console.log("refresh token was null. OAuth token is: " + oauth_token);
105+
if (oauth_token) {
106+
// OAuth token exists - use it to generate new access and refresh tokens:
107+
108+
new JSONRequester("GET", feedly_url + "/v3/auth/token",
109+
{
110+
"code": oauth_token,
111+
"client_id": client_id,
112+
"client_secret": client_secret,
113+
"redirect_uri": null, // TODO: change to localhost if this fails...
114+
"state": null,
115+
"grant_type": "authorization_code"
116+
},
117+
function(e) { // onload
118+
console.log("received e: " + e);
119+
// Save new access token:
120+
window.localStorage.setItem("access_token", e.access_token);
121+
window.localStorage.setItem("refresh_token", e.refresh_token);
122+
console.log("Got new refresh and access tokens from OAuth token");
123+
// Use access token in recursive call:
124+
return that.sendAuthenticated();
125+
},
126+
function(e) { // onerror
127+
console.log("OAuth was invalid.");
128+
window.localStorage.removeItem("oauth_token");
129+
configuration.logged_in = false;
130+
that.onerror(e);
131+
}
132+
).send();
133+
134+
return;
135+
}
136+
137+
console.log("NO LOGIN CREDENTIALS!!");
138+
}
139+
}

0 commit comments

Comments
 (0)