1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-11 18:35:49 +01:00

Pebble: use a proper event handling in the configuration JS

This allows more advanced configuration pages to work properly. The problematic config pages emerged while fixing #431
This commit is contained in:
Daniele Gobbetti 2016-11-24 18:03:47 +01:00
parent 67d89ce1b9
commit 5b804effa4
3 changed files with 43 additions and 35 deletions

View File

@ -1,5 +1,8 @@
###Changelog ###Changelog
####Version next
* Pebble: Further improve compatibility for watchface configuration
####Version 0.14.0 ####Version 0.14.0
* Pebble 2: Initial experimental support for P2/PT2 using BLE * 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) * Pebble: Special support in device discovery activity (MUST be used to get Pebble 2 working)

View File

@ -66,36 +66,38 @@ function gbPebble() {
this.configurationURL = null; this.configurationURL = null;
this.configurationValues = null; this.configurationValues = null;
var self = this; 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) { self.removeEventListener = function(name, handler) {
if(e == 'ready') { if (!self.events.hasOwnProperty(name))
self.ready = f; return;
}
if(e == 'showConfiguration') { var index = self.events[name].indexOf(handler);
self.showConfiguration = f; if (index != -1)
} self.events[name].splice(index, 1);
if(e == 'webviewclosed') { }
self.parseconfig = f;
} self.evaluate = function(name, args) {
if(e == 'appmessage') { console.log(args);
self.appmessage = f; 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() { this.actuallyOpenURL = function() {
showStep("step1compat"); showStep("step1compat");
window.open(self.configurationURL.toString(), "config"); window.open(self.configurationURL.toString(), "config");
@ -165,8 +167,6 @@ function gbPebble() {
GBjs.gbLog("app wanted to show: " + title + " body: "+ body); GBjs.gbLog("app wanted to show: " + title + " body: "+ body);
} }
this.ready = function() {
}
this.showConfiguration = function() { this.showConfiguration = function() {
console.error("This watchapp doesn't support configuration"); console.error("This watchapp doesn't support configuration");
@ -179,8 +179,8 @@ function gbPebble() {
if (str.split(needle)[1] !== undefined) { if (str.split(needle)[1] !== undefined) {
var t = new Object(); var t = new Object();
t.response = unescape(str.split(needle)[1]); t.response = decodeURIComponent(str.split(needle)[1]);
self.parseconfig(t); self.evaluate('webviewclosed',[t]);
showStep("step2"); showStep("step2");
} else { } else {
console.error("No valid configuration found in the entered string."); console.error("No valid configuration found in the entered string.");
@ -198,11 +198,13 @@ if (jsConfigFile != null) {
loadScript(jsConfigFile, function() { loadScript(jsConfigFile, function() {
if (getURLVariable('config') == 'true') { if (getURLVariable('config') == 'true') {
showStep("step2"); showStep("step2");
var json_string = unescape(getURLVariable('json')); var json_string = decodeURIComponent(getURLVariable('json'));
var t = new Object(); var t = new Object();
t.response = json_string; t.response = json_string;
if (json_string != '') if (json_string != '') {
Pebble.parseconfig(t); Pebble.evaluate('webviewclosed',[t]);
}
} else { } else {
if (storedPreset === undefined) { if (storedPreset === undefined) {
var presetElements = document.getElementsByClassName("load_presets"); var presetElements = document.getElementsByClassName("load_presets");
@ -210,8 +212,8 @@ if (jsConfigFile != null) {
presetElements[i].style.display = 'none'; presetElements[i].style.display = 'none';
} }
} }
Pebble.ready(); Pebble.evaluate('ready');
Pebble.showConfiguration(); Pebble.evaluate('showConfiguration');
} }
}); });
} }

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<changelog> <changelog>
<release version="next">
<change>Pebble: Further improve compatibility for watchface configuration</change>
</release>
<release version="0.14.0" versioncode="72"> <release version="0.14.0" versioncode="72">
<change>Pebble 2: Initial experimental support for P2/PT2 using BLE</change> <change>Pebble 2: Initial experimental support for P2/PT2 using BLE</change>
<change>Pebble: Special support in device discovery activity (MUST be used to get Pebble 2 working)</change> <change>Pebble: Special support in device discovery activity (MUST be used to get Pebble 2 working)</change>