From 692ff509e51e73d63952f737c12ab5d5e99008fc Mon Sep 17 00:00:00 2001
From: Gordon Williams
- Utilities
${escapeHtml(app.name)} (${version})
+${escapeHtml(app.name)} (${version.text})
${escapeHtml(app.description)}
C z7#S9UF>d`mMA@o*c2$HpbkT?>7*2Y*OJQT7lso}{^cW(^0}Oiverz%E+2+{2+Tk$b za4d}cE-Fgn`gIRRlO-~37CIDu|Io*=YX;KHu=BYPW{tI>$xWW2nJ5W<4RJb+?AwC*?of=q>vtHrqaG&QTrB8ioY9u=zHs(ctnA^a*4$Y zlQ26Z0h+sz)u{5;+WGO;r()iX)A3@K0)%!{zCe&yV0OKTG4mKY+eGZR1o)#Mfty%p zM^%rYlMf47ueJZjcn&}vJXnPyeuNx&8O66CiTsayM>D7+C#N*Z_(-SmL=!WujV8|j z1OZKLVN&&okhQff9@40scfYGc5kEl*tS7CkC)xZdq>w@i|3Cf(p6@7l7yKG+00000 LNkvXXu0mjf@;$L- literal 0 HcmV?d00001 diff --git a/apps/gpsrec/interface.html b/apps/gpsrec/interface.html new file mode 100644 index 000000000..cf6b2c311 --- /dev/null +++ b/apps/gpsrec/interface.html @@ -0,0 +1,37 @@ + + + + + + + Hello!
+ + + + diff --git a/apps/gpsrec/widget.js b/apps/gpsrec/widget.js new file mode 100644 index 000000000..84870a38e --- /dev/null +++ b/apps/gpsrec/widget.js @@ -0,0 +1,76 @@ +(() => { + // add the width + var xpos = WIDGETPOS.tl; + WIDGETPOS.tl += 24;/* the widget width plus some extra pixel to keep distance to others */; + var settings = {}; + var hasFix = false; + var fixToggle = false; // toggles once for each reading + var gpsTrack; // file for GPS track + var periodCtr = 0; + + // draw your widget at xpos + function draw() { + g.reset(); + g.setFont("4x6"); + g.setFontAlign(0,0); + g.clearRect(xpos,0,xpos+23,23); + + if (!settings.recording) { + g.setColor("#606060"); + } else { + g.setColor("#ff0000"); + if (hasFix) { + if (fixToggle) { + g.fillCircle(xpos+11,11,9); + g.setColor("#000000"); + } else + g.drawCircle(xpos+11,11,9); + } else { + g.setColor(fixToggle ? "#ff0000" : "#7f0000"); + g.drawString("NO",xpos+12,5); + g.drawString("FIX",xpos+12,19); + } + } + g.drawString("GPS",xpos+12,12); + } + + function onGPS(fix) { + hasFix = fix.fix; + fixToggle = !fixToggle; + draw(); + if (hasFix) { + periodCtr--; + if (periodCtr<=0) { + periodCtr = settings.period; + if (gpsTrack) gpsTrack.write([ + fix.time.getTime()|0, + fix.lat.toFixed(5), + fix.lon.toFixed(5), + fix.alt + ].join(",")+"\n"); + } + } + } + + // Called by the GPS app to reload settings and decide what's + function reload() { + settings = require("Storage").readJSON("@gpsrec")||{}; + settings.period = settings.period||1; + settings.file |= 0; + + Bangle.removeListener('GPS',onGPS); + if (settings.recording) { + Bangle.on('GPS',onGPS); + Bangle.setGPSPower(1); + var n = settings.file.toString(36); + gpsTrack = require("Storage").open(".gpsrc"+n,"a"); + } else { + Bangle.setGPSPower(0); + gpsTrack = undefined; + } + draw(); + } + reload(); + // add the widget + WIDGETS["gpsrec"]={draw:draw,reload:reload}; +})() diff --git a/index.js b/index.js index cb9352331..a4ec8799b 100644 --- a/index.js +++ b/index.js @@ -86,6 +86,8 @@ function showPrompt(title, text) { }); } function handleCustomApp(app) { + // Pops up an IFRAME that allows an app to be customised + if (!app.custom) throw new Error("App doesn't have custom HTML"); return new Promise((resolve,reject) => { var modal = htmlElement(`@@ -119,6 +121,58 @@ function handleCustomApp(app) { }, false); }); } + +function handleAppInterface(app) { + // IFRAME interface window that can be used to get data from the app + if (!app.interface) throw new Error("App doesn't have interface HTML"); + return new Promise((resolve,reject) => { + var modal = htmlElement(``); + document.body.append(modal); + htmlToArray(modal.getElementsByTagName("a")).forEach(button => { + button.addEventListener("click",event => { + event.preventDefault(); + modal.remove(); + //reject("Window closed"); + }); + }); + var iframe = modal.getElementsByTagName("iframe")[0]; + var iwin = iframe.contentWindow; + iwin.addEventListener("message", function(event) { + var msg = event.data; + if (msg.type=="eval") { + Puck.eval(msg.data, function(result) { + iwin.postMessage({ + type : "evalrsp", + data : result, + id : msg.id + }); + }); + } else if (msg.type=="write") { + Puck.write(msg.data, function() { + iwin.postMessage({ + type : "writersp", + id : msg.id + }); + }); + } + }, false); + iframe.src = `apps/${app.id}/${app.interface}` + }); +} + // =========================================== Top Navigation function showTab(tabname) { htmlToArray(document.querySelectorAll("#tab-navigate .tab-item")).forEach(tab => { @@ -162,6 +216,7 @@ function refreshLibrary() {${escapeHtml(app.description)}
+ @@ -236,6 +291,8 @@ function refreshLibrary() { icon.classList.remove("icon-refresh"); icon.classList.add("loading"); updateApp(app); + } else if (icon.classList.contains("icon-download")) { + handleAppInterface(app); } }); }); @@ -272,6 +329,7 @@ function updateApp(app) { }); } + function appNameToApp(appName) { var app = appJSON.find(app=>app.id==appName); if (app) return app; @@ -301,9 +359,9 @@ function refreshMyApps() { var panelbody = document.querySelector("#myappscontainer .panel-body"); var tab = document.querySelector("#tab-myappscontainer a"); tab.setAttribute("data-badge", appsInstalled.length); - panelbody.innerHTML = appsInstalled.map(appJSON => { -var app = appNameToApp(appJSON.id); -var version = getVersionInfo(app, appJSON); + panelbody.innerHTML = appsInstalled.map(appInstalled => { +var app = appNameToApp(appInstalled.id); +var version = getVersionInfo(app, appInstalled); return `