classic-lite

Minimalist rewrite of Łukasz Zalewski's "classic" pebble watchface
git clone https://git.instinctive.eu/classic-lite.git
Log | Files | Refs | README | LICENSE

pebble-js-app.js (3475B)


      1 /*
      2  * Copyright (c) 2015, Natacha Porté
      3  *
      4  * Permission to use, copy, modify, and distribute this software for any
      5  * purpose with or without fee is hereby granted, provided that the above
      6  * copyright notice and this permission notice appear in all copies.
      7  *
      8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 const settings = {  /* "name in local storage": "form input parameter" */
     18   "backgroundColor":     "background",
     19   "hourHandColor":       "hhand",
     20   "minuteHandColor":     "mhand",
     21   "pinColor":            "pin",
     22   "hourColor":           "hours",
     23   "innerColor":          "inner",
     24   "minuteColor":         "minutes",
     25   "lowBatteryLevel":     "battlvl",
     26   "batteryColor":        "battcol",
     27   "batteryColor2":       "battcol2",
     28   "bluetoothColor":      "bluetooth",
     29   "bluetoothVibration":  "vibrate",
     30   "textColor":           "textcol",
     31   "textFormat":          "textfmt",
     32   "textFont":            "font",
     33 };
     34 
     35 function encodeStored(names) {
     36   var handColorValue = localStorage.getItem("handColor");
     37   if (handColorValue != null) {
     38     if (localStorage.getItem("hourHandColor") == null) {
     39       localStorage.setItem("hourHandColor", handColorValue);
     40     }
     41     if (localStorage.getItem("minuteHandColor") == null) {
     42       localStorage.setItem("minuteHandColor", handColorValue);
     43     }
     44     if (localStorage.getItem("pinColor") == null) {
     45       localStorage.setItem("pinColor", handColorValue);
     46     }
     47     localStorage.removeItem("handColor");
     48   }
     49 
     50   var result = "?v=1.5";
     51   for (var key in names) {
     52     var value = localStorage.getItem(key);
     53     if (value != null) {
     54       result = result + "&" + names[key] + "=" + encodeURIComponent(value);
     55     }
     56   }
     57   return result;
     58 }
     59 
     60 Pebble.addEventListener("ready", function() {
     61   console.log("Classic-Lite PebbleKit JS ready!");
     62 });
     63 
     64 Pebble.addEventListener("showConfiguration", function() {
     65   Pebble.openURL("https://cdn.rawgit.com/faelys/classic-lite/v1.4/config.html" + encodeStored(settings));
     66 });
     67 
     68 Pebble.addEventListener("webviewclosed", function(e) {
     69   var configData = JSON.parse(decodeURIComponent(e.response));
     70 
     71   for (var key in settings) {
     72     localStorage.setItem(key, configData[key]);
     73   }
     74 
     75   var dict = {
     76     1: parseInt(configData["backgroundColor"]),
     77     2: parseInt(configData["batteryColor"]),
     78     3: parseInt(configData["bluetoothColor"]),
     79     5: parseInt(configData["hourColor"]),
     80     6: parseInt(configData["innerColor"]),
     81     7: parseInt(configData["minuteColor"]),
     82     8: parseInt(configData["textColor"]),
     83     9: parseInt(configData["batteryColor2"]),
     84     10: parseInt(configData["textFont"]),
     85     11: configData["textFormat"],
     86     12: parseInt(configData["bluetoothVibration"]),
     87     13: parseInt(configData["lowBatteryLevel"]),
     88     20: parseInt(configData["hourHandColor"]),
     89     21: parseInt(configData["minuteHandColor"]),
     90     22: parseInt(configData["pinColor"]),
     91   };
     92 
     93   Pebble.sendAppMessage(dict, function() {
     94     console.log("Send successful: " + JSON.stringify(dict));
     95   }, function() {
     96     console.log("Send failed!");
     97   });
     98 });