Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pebble-js-app.js « js « src - github.com/ClusterM/pebble-mario.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4638ce83a68acf4cd62b25d610a6d35c168b97f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var initialized = false;
var options = {
  "config_show_no_phone": true,
  "config_show_battery": true,
  "config_show_phone_battery": true,
  "config_vibe": false,
};

Pebble.addEventListener("ready", function() {
  initialized = true;
	var json = window.localStorage.getItem('mario-config');	
	if (typeof json === 'string') {
		try {
      options = JSON.parse(json);
			Pebble.sendAppMessage(options);
			console.log("Loaded stored config: " + json);
    } catch(e) {
      console.log("stored config json parse error: " + json + ' - ' + e);
    }
  }
});

Pebble.addEventListener("showConfiguration", function() {
  console.log("showing configuration");
	var cfg = '?config=' + encodeURI(JSON.stringify(options));
  Pebble.openURL("http://clusterrr.com/pebble_configs/mario.php" + cfg);
});

Pebble.addEventListener("webviewclosed", function(e) {
	var response = decodeURIComponent(e.response);
  if (response.charAt(0) == "{" && response.slice(-1) == "}" && response.length > 5) {
    window.localStorage.setItem('mario-config', response);
		try {
			options = JSON.parse(response);
			Pebble.sendAppMessage(options);
    } catch(e) {
			console.log("Response config json parse error: " + response + ' - ' + e);
		}
    console.log("Options = " + response);
  }
});