From d5586478f3dd0572036755abe375a808c8907f37 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Fri, 17 Jun 2016 17:47:13 +0200 Subject: [PATCH] Support legacy configuration pages #251 There are pages that do not honor return_to get parameter. This commit allows the user to enter the returned url manually. --- app/src/main/assets/app_config/configure.html | 21 ++++++++++++++++++- .../app_config/js/gadgetbridge_boilerplate.js | 21 ++++++++++++++++++- .../activities/ExternalPebbleJSActivity.java | 8 +++++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/app_config/configure.html b/app/src/main/assets/app_config/configure.html index 14e4d7fd..87188f12 100644 --- a/app/src/main/assets/app_config/configure.html +++ b/app/src/main/assets/app_config/configure.html @@ -19,7 +19,8 @@ } #config_url,#jsondata { word-wrap: break-word; - margin: 20px; + margin: 20px 0; + width: 90%; } .btn { display: inline-block; @@ -38,6 +39,16 @@ box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2)inset; transition-delay: 0s; } + p { + width: 90%; + } + #pastereturn { + width: 90%; + min-height: 3em; + } + #step1compat, #step2 { + display: none; + } @@ -48,6 +59,14 @@ +
+

In case of "network error" after saving settings in the wathchapp, copy the "network error" + URL and paste it here:

+
+ +

Incoming configuration data:

diff --git a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js index df85886d..a40bf2d7 100644 --- a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js +++ b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js @@ -63,6 +63,7 @@ function gbPebble() { } } this.actuallyOpenURL = function() { + document.getElementById('step1compat').style.display="block"; window.open(this.configurationURL.toString(), "config"); } @@ -114,6 +115,22 @@ function gbPebble() { this.ready = function() { } + this.parseReturnedPebbleJS = function() { + + var str = document.getElementById('pastereturn').value; + var needle = "pebblejs://close#"; + + if (str.split(needle)[1] !== undefined) { + var t = new Object(); + t.response = unescape(str.split(needle)[1]); + this.parseconfig(t); + document.getElementById('step1').style.display="none"; + document.getElementById('step1compat').style.display="none"; + document.getElementById('step2').style.display="block"; + } else { + console.error("No valid configuration found in the entered string."); + } + } } var Pebble = new gbPebble(); @@ -123,13 +140,15 @@ if (jsConfigFile != null) { loadScript(jsConfigFile, function() { if (getURLVariable('config') == 'true') { document.getElementById('step1').style.display="none"; + document.getElementById('step1compat').style.display="none"; + document.getElementById('step2').style.display="block"; + var json_string = unescape(getURLVariable('json')); var t = new Object(); t.response = json_string; if (json_string != '') Pebble.parseconfig(t); } else { - document.getElementById('step2').style.display="none"; Pebble.ready(); Pebble.showConfiguration(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index a5181dcc..f2d30264 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -54,8 +54,12 @@ public class ExternalPebbleJSActivity extends GBActivity { Uri uri = getIntent().getData(); if (uri != null) { //getting back with configuration data - appUuid = UUID.fromString(uri.getHost()); - queryString = uri.getEncodedQuery(); + try { + appUuid = UUID.fromString(uri.getHost()); + queryString = uri.getEncodedQuery(); + } catch (IllegalArgumentException e) { + Log.d("returned uri: ", uri.toString()); + } } else { appUuid = (UUID) getIntent().getSerializableExtra("app_uuid"); }