From 827a401e1c120c60178d95f9371159a426128c2b Mon Sep 17 00:00:00 2001 From: alanacheff Date: Sun, 6 Oct 2024 20:53:15 +0000 Subject: [PATCH] Upload files to "src/pkjs" --- src/pkjs/app.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/pkjs/app.js diff --git a/src/pkjs/app.js b/src/pkjs/app.js new file mode 100644 index 0000000..01b42a4 --- /dev/null +++ b/src/pkjs/app.js @@ -0,0 +1,79 @@ +var BASE_CONFIG_URL = 'http://singleserveapps.github.io/basic-steps-config/'; +//var BASE_CONFIG_URL = 'http://singleserveapps.github.io/basic-steps-config-beta/'; + +Pebble.addEventListener('showConfiguration', function() { + var rectURL = BASE_CONFIG_URL + 'index.html'; + var roundURL = BASE_CONFIG_URL + 'config_round.html'; + var watch; + + if(Pebble.getActiveWatchInfo) { + try { + watch = Pebble.getActiveWatchInfo(); + } catch(err) { + watch = { + platform: "basalt", + }; + } + } else { + watch = { + platform: "aplite", + }; + } + + if(watch.platform == "aplite"){ + Pebble.openURL(rectURL); + } else if(watch.platform == "chalk") { + Pebble.openURL(roundURL); + } else { + Pebble.openURL(rectURL); + } +}); + +Pebble.addEventListener('webviewclosed', function(e) { + var configData = JSON.parse(decodeURIComponent(e.response)); + + console.log('Configuration page returned: ' + JSON.stringify(configData)); + + if (!configData.displayDigitalTime) { + console.log("hrColor: ", parseInt(configData.hrColor, 16)); + console.log("minColor: ", parseInt(configData.minColor, 16)); + console.log("wsdColor: ", parseInt(configData.wsdColor, 16)); + console.log("backgroundColor: ", parseInt(configData.backgroundColor, 16)); + console.log("hourFont: ", parseInt(configData.hourFont, 10)); + console.log("minutesFont: ", parseInt(configData.minutesFont, 10)); + + // Assemble dictionary using our keys + var options_dictionary = { + "KEY_HR_COLOR": parseInt(configData.hrColor, 16), + "KEY_MIN_COLOR": parseInt(configData.minColor, 16), + "KEY_WSD_COLOR": parseInt(configData.wsdColor, 16), + "KEY_BACKGROUND_COLOR": parseInt(configData.backgroundColor, 16), + "KEY_HOUR_FONT": parseInt(configData.hourFont, 10), + "KEY_MINUTES_FONT": parseInt(configData.minutesFont, 10) + }; + + // Send to Pebble + Pebble.sendAppMessage(options_dictionary, + function(e) { + console.log("webviewclosed: Watchface options successfully sent to Pebble"); + }, + function(e) { + console.log('webviewclosed: Unable to deliver message with transactionId=' + e.data.transactionId + ' Error is: ' + e.error.message); + } + ); + } +}); + +Pebble.addEventListener('ready', function() { + console.log('PebbleKit JS Ready!'); + + // Notify the watchapp that it is now safe to send messages + Pebble.sendAppMessage({ 'KEY_JS_READY': 1 }); + +}); + +Pebble.addEventListener('appmessage', + function(e) { + console.log("Got message: " + JSON.stringify(e)); + } +); \ No newline at end of file