From ed4137837ae63c8fca781b6233eed34655fab724 Mon Sep 17 00:00:00 2001 From: bahbka Date: Mon, 28 Jul 2014 12:11:04 +0400 Subject: Workaround for APP_MSG_INTERNAL_ERROR. --- Makefile | 2 +- README.md | 3 +++ appinfo.json | 4 ++-- resources/configuration.html | 2 +- src/js/pebble-js-app.src.js | 42 +++++++++++++++++++++++++----------------- src/pebble-my-data.c | 6 ++++-- stuff/pebble-my-data.pbw | Bin 32405 -> 32372 bytes 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 0e41d34..60e1ab0 100644 --- a/Makefile +++ b/Makefile @@ -14,5 +14,5 @@ build/pebble-my-data.pbw: src/js/pebble-js-app.js src/pebble-my-data.c appinfo.j pebble build src/js/pebble-js-app.js: src/js/pebble-js-app.src.js resources/configuration.html - perl -pe 'BEGIN { local $$/; open $$fh,pop @ARGV or die $$!; $$f = <$$fh>; $$f =~ s/\047/\\\047/g; } s/_HTMLMARKER_/$$f/g;' $^ | uglifyjs > $@ + perl -pe 'BEGIN { local $$/; open $$fh,pop @ARGV or die $$!; $$f = <$$fh>; $$f =~ s/\047/\\\047/g; $$f =~ s/\n//g; } s/_HTMLMARKER_/$$f/g;' $^ | uglifyjs > $@ diff --git a/README.md b/README.md index 666d3ca..6909566 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ Inspired by [Pebble Cards](http://keanulee.com/pebblecards). ## Changelog +### 2.3.4 +- Workaround for APP_MSG_INTERNAL_ERROR (request last response after 0.1s if occur) + ### 2.3.3 - Extract fields from any level of JSON (useful with [KimonoLabs API](https://www.kimonolabs.com)); multiple content fields will be concatenated with '\n\n'; other fields will be converted to integer, first copy will be used - Don't schedule update if another one already in progress diff --git a/appinfo.json b/appinfo.json index 0e7eed2..01d9b1e 100644 --- a/appinfo.json +++ b/appinfo.json @@ -3,8 +3,8 @@ "shortName": "My Data", "longName": "My Data", "companyName": "bahbka", - "versionCode": 233, - "versionLabel": "2.3.3", + "versionCode": 234, + "versionLabel": "2.3.4", "watchapp": { "watchface": false }, diff --git a/resources/configuration.html b/resources/configuration.html index 6adb9bb..cf5d8a1 100644 --- a/resources/configuration.html +++ b/resources/configuration.html @@ -63,7 +63,7 @@ vim: sw=2 ts=2 expandtab ai

My Data

- v2.3.3, by bahbka + v2.3.4, by bahbka
diff --git a/src/js/pebble-js-app.src.js b/src/js/pebble-js-app.src.js index 0be03ec..ad12514 100644 --- a/src/js/pebble-js-app.src.js +++ b/src/js/pebble-js-app.src.js @@ -12,7 +12,8 @@ var MSG = { SHAKE_UPDATE: 7, JSON_RESPONSE: 8, CONFIG: 9, - ERROR: 10 + ERROR: 10, + IN_RETRY: 11 }; var CONTENT_MAX_LENGTH = 900; @@ -98,6 +99,7 @@ function http_request(url) { response["content"] = response["content"].substring(0, CONTENT_MAX_LENGTH); } + window.localStorage.setItem('pebble-my-data-response', JSON.stringify(response)); Pebble.sendAppMessage(response); if (response["auth"] != null) { @@ -188,23 +190,29 @@ Pebble.addEventListener("appmessage", var url = config["url"]; var s = (url.indexOf("?")===-1)?"?":"&"; - if (e.payload["refresh"] == MSG.SELECT_SHORT_PRESS_UPDATE) { - url = url + s + "select=1"; - } else if (e.payload["refresh"] == MSG.SELECT_LONG_PRESS_UPDATE) { - url = url + s + "select=2"; - } else if (e.payload["refresh"] == MSG.UP_SHORT_PRESS_UPDATE) { - url = url + s + "up=1"; - } else if (e.payload["refresh"] == MSG.UP_LONG_PRESS_UPDATE) { - url = url + s + "up=2"; - } else if (e.payload["refresh"] == MSG.DOWN_SHORT_PRESS_UPDATE) { - url = url + s + "down=1"; - } else if (e.payload["refresh"] == MSG.DOWN_LONG_PRESS_UPDATE) { - url = url + s + "down=2"; - } else if (e.payload["refresh"] == MSG.SHAKE_UPDATE) { - url = url + s + "shake=1"; - } + if (e.payload["refresh"] == MSG.IN_RETRY) { + response = window.localStorage.getItem('pebble-my-data-response'); + Pebble.sendAppMessage(JSON.parse(response)); - fetch_data(url); + } else { + if (e.payload["refresh"] == MSG.SELECT_SHORT_PRESS_UPDATE) { + url = url + s + "select=1"; + } else if (e.payload["refresh"] == MSG.SELECT_LONG_PRESS_UPDATE) { + url = url + s + "select=2"; + } else if (e.payload["refresh"] == MSG.UP_SHORT_PRESS_UPDATE) { + url = url + s + "up=1"; + } else if (e.payload["refresh"] == MSG.UP_LONG_PRESS_UPDATE) { + url = url + s + "up=2"; + } else if (e.payload["refresh"] == MSG.DOWN_SHORT_PRESS_UPDATE) { + url = url + s + "down=1"; + } else if (e.payload["refresh"] == MSG.DOWN_LONG_PRESS_UPDATE) { + url = url + s + "down=2"; + } else if (e.payload["refresh"] == MSG.SHAKE_UPDATE) { + url = url + s + "shake=1"; + } + + fetch_data(url); + } } else { Pebble.sendAppMessage({ "msg_type": MSG.JSON_RESPONSE, "content": "URL not defined, check settings in Pebble App" }); diff --git a/src/pebble-my-data.c b/src/pebble-my-data.c index ac701c6..4bbf371 100644 --- a/src/pebble-my-data.c +++ b/src/pebble-my-data.c @@ -54,6 +54,7 @@ bool update_in_progress = false; #define DEFAULT_REFRESH 300*1000 #define RETRY_DELAY 60*1000 +#define IN_RETRY_DELAY 100 #define REQUEST_TIMEOUT 30*1000 #define BLINK_INTERVAL 500 @@ -93,7 +94,8 @@ enum { // msg type MSG_SHAKE_UPDATE, MSG_JSON_RESPONSE, MSG_CONFIG, - MSG_ERROR + MSG_ERROR, + MSG_IN_RETRY }; enum { // themes @@ -486,7 +488,7 @@ void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, voi void in_dropped_handler(AppMessageResult reason, void *context) { bitmap_layer_set_bitmap(update_icon_layer, update_error_icon_bitmap); update_in_progress = false; - schedule_update(RETRY_DELAY, update_type); + schedule_update(IN_RETRY_DELAY, MSG_IN_RETRY); } // process received data diff --git a/stuff/pebble-my-data.pbw b/stuff/pebble-my-data.pbw index f8dee0a..9468074 100644 Binary files a/stuff/pebble-my-data.pbw and b/stuff/pebble-my-data.pbw differ -- cgit v1.2.3