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

commit bb3426807b08ac7fc33be568fe441dd8fd515ead
parent 2a14c7a9bbe7a4ee7155aced3d79f7194004edb0
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date:   Mon,  7 Dec 2015 18:11:23 +0000

Use localStorage and parameter parsing to keep UI settings

Note that localStorage is used in `pebble-js-app.js` rather than directly
in `config.html` because the latter has a localStorage shared with all
pages from `cdn.rawgit.com`, including other apps.
Diffstat:
Mconfig.html | 16+++++++++++++++-
Msrc/js/pebble-js-app.js | 33++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/config.html b/config.html @@ -83,7 +83,7 @@ <div class="item-container-header">Low Battery Warning</div> <div class="item-container-content"> <label class="item"> - <input type="range" class="item-slider" name="lowBatteryLevel" value="50"> + <input type="range" id="lowBatteryLevelSlider" class="item-slider" name="lowBatteryLevel" value="50"> <div class="item-input-wrapper item-slider-text"> <input type="text" id="lowBatteryLevel" class="item-input" name="lowBatteryLevel" value="50"> </div> @@ -140,5 +140,19 @@ </div> <script src="https://cdn.rawgit.com/pebble/slate/v0.0.3/dist/js/slate.min.js"></script> + <script> + document.getElementById("backgroundColorPicker").value = getQueryParam("background", "0xFFFFFF"); + document.getElementById("handColorPicker").value = getQueryParam("hands", "0x000000"); + document.getElementById("hourColorPicker").value = getQueryParam("hours", "0x000000"); + document.getElementById("innerColorPicker").value = getQueryParam("inner", "0xAAAAAA"); + document.getElementById("minuteColorPicker").value = getQueryParam("minutes", "0x000000"); + document.getElementById("lowBatteryLevelSlider").value = + document.getElementById("lowBatteryLevel").value = getQueryParam("battlvl", "50"); + document.getElementById("batteryColorPicker").value = getQueryParam("battcol", "0x555555"); + document.getElementById("bluetoothColorPicker").value = getQueryParam("bluetooth", "0x000000"); + document.getElementById("bluetoothVibration").checked = (parseInt(getQueryParam("vibrate", "1")) > 0); + document.getElementById("textColorPicker").value = getQueryParam("textcol", "0x000000"); + document.getElementById("textFormat").value = getQueryParam("textfmt", "Pebble"); + </script> </body> </html> diff --git a/src/js/pebble-js-app.js b/src/js/pebble-js-app.js @@ -1,3 +1,30 @@ +const settings = { /* "name in local storage": "form input parameter" */ + "backgroundColor": "background", + "handColor": "hands", + "hourColor": "hours", + "innerColor": "inner", + "minuteColor": "minutes", + "lowBatteryLevel": "battlvl", + "batteryColor": "battcol", + "bluetoothColor": "bluetooth", + "bluetoothVibration": "vibrate", + "textColor": "textcol", + "textFormat": "textfmt", +}; + +function encodeStored(names) { + var first = true; + var result = ""; + for (var key in names) { + var value = localStorage.getItem(key); + if (value != null) { + result = result + (first ? "?" : "&") + names[key] + "=" + encodeURIComponent(value); + first = false; + } + } + return result; +} + Pebble.addEventListener("ready", function() { console.log("Classic-Lite PebbleKit JS ready!"); }); @@ -6,12 +33,16 @@ Pebble.addEventListener("showConfiguration", function() { /* TODO: switch to release version: Pebble.openURL("https://cdn.rawgit.com/faelys/classic-lite/v1.0/config.html"); */ - Pebble.openURL("https://rawgit.com/faelys/classic-lite/master/config.html"); + Pebble.openURL("https://rawgit.com/faelys/classic-lite/trunk/config.html" + encodeStored(settings)); }); Pebble.addEventListener("webviewclosed", function(e) { var configData = JSON.parse(decodeURIComponent(e.response)); + for (var key in settings) { + localStorage.setItem(key, configData[key]); + } + var dict = { 1: parseInt(configData["backgroundColor"]), 2: parseInt(configData["batteryColor"]),