diff --git a/CHANGELOG.md b/CHANGELOG.md index 985f1161b..b50b67090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ###Changelog +####Version next +* Pebble: Further improve compatibility for watchface configuration + ####Version 0.14.0 * Pebble 2: Initial experimental support for P2/PT2 using BLE * Pebble: Special support in device discovery activity (MUST be used to get Pebble 2 working) 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 035fd08c4..0c51b1ddd 100644 --- a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js +++ b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js @@ -66,36 +66,38 @@ function gbPebble() { this.configurationURL = null; this.configurationValues = null; var self = this; + self.events = {}; + //events processing: see http://stackoverflow.com/questions/10978311/implementing-events-in-my-own-object + self.addEventListener = function(name, handler) { + if (self.events.hasOwnProperty(name)) + self.events[name].push(handler); + else + self.events[name] = [handler]; + } - this.addEventListener = function(e, f) { - if(e == 'ready') { - self.ready = f; - } - if(e == 'showConfiguration') { - self.showConfiguration = f; - } - if(e == 'webviewclosed') { - self.parseconfig = f; - } - if(e == 'appmessage') { - self.appmessage = f; + self.removeEventListener = function(name, handler) { + if (!self.events.hasOwnProperty(name)) + return; + + var index = self.events[name].indexOf(handler); + if (index != -1) + self.events[name].splice(index, 1); + } + + self.evaluate = function(name, args) { + console.log(args); + if (!self.events.hasOwnProperty(name)) + return; + + if (!args || !args.length) + args = []; + + var evs = self.events[name], l = evs.length; + for (var i = 0; i < l; i++) { + evs[i].apply(null, args); } } - this.removeEventListener = function(e, f) { - if(e == 'ready') { - self.ready = null; - } - if(e == 'showConfiguration') { - self.showConfiguration = null; - } - if(e == 'webviewclosed') { - self.parseconfig = null; - } - if(e == 'appmessage') { - self.appmessage = null; - } - } this.actuallyOpenURL = function() { showStep("step1compat"); window.open(self.configurationURL.toString(), "config"); @@ -165,8 +167,6 @@ function gbPebble() { GBjs.gbLog("app wanted to show: " + title + " body: "+ body); } - this.ready = function() { - } this.showConfiguration = function() { console.error("This watchapp doesn't support configuration"); @@ -179,8 +179,8 @@ function gbPebble() { if (str.split(needle)[1] !== undefined) { var t = new Object(); - t.response = unescape(str.split(needle)[1]); - self.parseconfig(t); + t.response = decodeURIComponent(str.split(needle)[1]); + self.evaluate('webviewclosed',[t]); showStep("step2"); } else { console.error("No valid configuration found in the entered string."); @@ -198,11 +198,13 @@ if (jsConfigFile != null) { loadScript(jsConfigFile, function() { if (getURLVariable('config') == 'true') { showStep("step2"); - var json_string = unescape(getURLVariable('json')); + var json_string = decodeURIComponent(getURLVariable('json')); var t = new Object(); t.response = json_string; - if (json_string != '') - Pebble.parseconfig(t); + if (json_string != '') { + Pebble.evaluate('webviewclosed',[t]); + } + } else { if (storedPreset === undefined) { var presetElements = document.getElementsByClassName("load_presets"); @@ -210,8 +212,8 @@ if (jsConfigFile != null) { presetElements[i].style.display = 'none'; } } - Pebble.ready(); - Pebble.showConfiguration(); + Pebble.evaluate('ready'); + Pebble.evaluate('showConfiguration'); } }); } diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index bd975b902..c742ed415 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -1,5 +1,8 @@ + + Pebble: Further improve compatibility for watchface configuration + Pebble 2: Initial experimental support for P2/PT2 using BLE Pebble: Special support in device discovery activity (MUST be used to get Pebble 2 working)