mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 01:25:50 +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:
parent
67d89ce1b9
commit
5b804effa4
@ -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)
|
||||
|
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<changelog>
|
||||
<release version="next">
|
||||
<change>Pebble: Further improve compatibility for watchface configuration</change>
|
||||
</release>
|
||||
<release version="0.14.0" versioncode="72">
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user