Note that aborting configuration (using the back button) doesn't
trigger any notification, so there is no way to know configuration
ended that way.
Also note that the loading of configuration is not fast enough to
prevent auto-close when there is no data yet to transmit.
| ... | ... |
@@ -132,6 +132,8 @@ Pebble.addEventListener("appmessage", function(e) {
|
| 132 | 132 |
Pebble.addEventListener("showConfiguration", function() {
|
| 133 | 133 |
var settings = "?v=1.0"; |
| 134 | 134 |
|
| 135 |
+ Pebble.sendAppMessage({ "cfgStart": 1 });
|
|
| 136 |
+ |
|
| 135 | 137 |
if (cfg_endpoint) {
|
| 136 | 138 |
settings += "&url=" + encodeURIComponent(cfg_endpoint); |
| 137 | 139 |
} |
| ... | ... |
@@ -162,6 +164,7 @@ Pebble.addEventListener("showConfiguration", function() {
|
| 162 | 164 |
Pebble.addEventListener("webviewclosed", function(e) {
|
| 163 | 165 |
var configData = JSON.parse(decodeURIComponent(e.response)); |
| 164 | 166 |
var wasConfigured = (cfg_endpoint && cfg_data_field); |
| 167 |
+ var msg = { "cfgEnd": 1 };
|
|
| 165 | 168 |
|
| 166 | 169 |
if (configData.url) {
|
| 167 | 170 |
cfg_endpoint = configData.url; |
| ... | ... |
@@ -212,7 +215,7 @@ Pebble.addEventListener("webviewclosed", function(e) {
|
| 212 | 215 |
if (configData.autoClose !== null) {
|
| 213 | 216 |
cfg_auto_close = configData.autoClose; |
| 214 | 217 |
localStorage.setItem("cfgAutoClose", cfg_auto_close);
|
| 215 |
- Pebble.sendAppMessage({ "cfgAutoClose": cfg_auto_close ? 1 : 0 });
|
|
| 218 |
+ msg.cfgAutoClose = cfg_auto_close ? 1 : 0; |
|
| 216 | 219 |
} |
| 217 | 220 |
|
| 218 | 221 |
console.log(cfg_sign_field ? "Signature enabled" : "Signature disabled"); |
| ... | ... |
@@ -227,6 +230,8 @@ Pebble.addEventListener("webviewclosed", function(e) {
|
| 227 | 230 |
} |
| 228 | 231 |
|
| 229 | 232 |
if (!wasConfigured && cfg_endpoint && cfg_data_field) {
|
| 230 |
- Pebble.sendAppMessage({ "lastSent": 0 });
|
|
| 233 |
+ msg.lastSent = 0; |
|
| 231 | 234 |
} |
| 235 |
+ |
|
| 236 |
+ Pebble.sendAppMessage(msg); |
|
| 232 | 237 |
}); |
| ... | ... |
@@ -26,6 +26,8 @@ |
| 26 | 26 |
#define MSG_KEY_UPLOAD_START 140 |
| 27 | 27 |
#define MSG_KEY_DATA_KEY 210 |
| 28 | 28 |
#define MSG_KEY_DATA_LINE 220 |
| 29 |
+#define MSG_KEY_CFG_START 301 |
|
| 30 |
+#define MSG_KEY_CFG_END 302 |
|
| 29 | 31 |
#define MSG_KEY_CFG_AUTO_CLOSE 310 |
| 30 | 32 |
|
| 31 | 33 |
static Window *window; |
| ... | ... |
@@ -40,7 +42,9 @@ static bool modal_displayed = false; |
| 40 | 42 |
static bool display_dirty = false; |
| 41 | 43 |
static char global_buffer[1024]; |
| 42 | 44 |
static bool sending_data = false; |
| 45 |
+static bool cfg_auto_close = false; |
|
| 43 | 46 |
static bool auto_close = false; |
| 47 |
+static bool configuring = false; |
|
| 44 | 48 |
|
| 45 | 49 |
static struct widget {
|
| 46 | 50 |
char label[64]; |
| ... | ... |
@@ -463,12 +467,26 @@ inbox_received_handler(DictionaryIterator *iterator, void *context) {
|
| 463 | 467 |
|
| 464 | 468 |
tuple = dict_find(iterator, MSG_KEY_CFG_AUTO_CLOSE); |
| 465 | 469 |
if (tuple) {
|
| 466 |
- auto_close = (tuple_uint(tuple) != 0); |
|
| 470 |
+ auto_close = cfg_auto_close = (tuple_uint(tuple) != 0); |
|
| 467 | 471 |
persist_write_bool(MSG_KEY_CFG_AUTO_CLOSE, auto_close); |
| 468 | 472 |
if (auto_close && !sending_data |
| 469 | 473 |
&& web.current_key >= phone.current_key) |
| 470 | 474 |
close_app(); |
| 471 | 475 |
} |
| 476 |
+ |
|
| 477 |
+ tuple = dict_find(iterator, MSG_KEY_CFG_START); |
|
| 478 |
+ if (tuple) {
|
|
| 479 |
+ APP_LOG(APP_LOG_LEVEL_INFO, "Starting configuration"); |
|
| 480 |
+ auto_close = false; |
|
| 481 |
+ configuring = true; |
|
| 482 |
+ } |
|
| 483 |
+ |
|
| 484 |
+ tuple = dict_find(iterator, MSG_KEY_CFG_END); |
|
| 485 |
+ if (tuple) {
|
|
| 486 |
+ APP_LOG(APP_LOG_LEVEL_INFO, "End of configuration"); |
|
| 487 |
+ auto_close = cfg_auto_close; |
|
| 488 |
+ configuring = false; |
|
| 489 |
+ } |
|
| 472 | 490 |
} |
| 473 | 491 |
|
| 474 | 492 |
static void |
| ... | ... |
@@ -495,9 +513,7 @@ tick_handler(struct tm *tick_time, TimeUnits units_changed) {
|
| 495 | 513 |
|
| 496 | 514 |
static void |
| 497 | 515 |
init(void) {
|
| 498 |
- auto_close = persist_read_bool(MSG_KEY_CFG_AUTO_CLOSE); |
|
| 499 |
- APP_LOG(APP_LOG_LEVEL_INFO, "auto_close initialized to %s", |
|
| 500 |
- auto_close ? "true" : "false"); |
|
| 516 |
+ cfg_auto_close = persist_read_bool(MSG_KEY_CFG_AUTO_CLOSE); |
|
| 501 | 517 |
|
| 502 | 518 |
app_message_register_inbox_received(inbox_received_handler); |
| 503 | 519 |
app_message_register_outbox_failed(outbox_failed_handler); |