diff --git a/apps.json b/apps.json index a0a819ca5..09477d72a 100644 --- a/apps.json +++ b/apps.json @@ -4,7 +4,7 @@ "tags": "tool,system", "type":"bootloader", "icon": "bootloader.png", - "version":"0.23", + "version":"0.24", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "storage": [ {"name":".boot0","url":"boot0.js"}, @@ -42,7 +42,7 @@ "name": "Launcher (Default)", "shortName":"Launcher", "icon": "app.png", - "version":"0.05", + "version":"0.06", "description": "This is needed by Bangle.js to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.", "tags": "tool,system,launcher", "type":"launch", diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index adfdb2709..a176df670 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -22,3 +22,4 @@ 0.21: Handle echo off char from Gadgetbridge app when programmable:off (fix #558) 0.22: Stop LCD timeout being disabled on first run (when there is no settings.json) 0.23: Move to a precalculated .boot0 file which should speed up load time +0.24: Add Bangle.setUI polyfill diff --git a/apps/boot/bootupdate.js b/apps/boot/bootupdate.js index 4f380b948..9dc90cc9a 100644 --- a/apps/boot/bootupdate.js +++ b/apps/boot/bootupdate.js @@ -79,10 +79,48 @@ if (s.quiet && s.qmBrightness) { if (s.quiet && s.qmTimeout) boot+=`Bangle.setLCDTimeout(${s.qmTimeout});\n`; if (s.passkey!==undefined && s.passkey.length==6) boot+=`NRF.setSecurity({passkey:${s.passkey}, mitm:1, display:1});\n`; if (s.whitelist) boot+=`NRF.on('connect', function(addr) { if (!(require('Storage').readJSON('setting.json',1)||{}).whitelist.includes(addr)) NRF.disconnect(); });\n`; -// Pre-2v10 firmwares without a theme +// Pre-2v10 firmwares without a theme/setUI if (!g.theme) { boot += `g.theme={fg:-1,bg:0,fg2:-1,bg2:7,fgH:-1,bgH:0x02F7};\n`; } +if (!Bangle.setUI) { + boot += `Bangle.setUI=function(mode, cb) { +if (Bangle.btnWatches) { + Bangle.btnWatches.forEach(clearWatch); + delete Bangle.btnWatches; +} +if (Bangle.swipeHandler) { + Bangle.removeListener("swipe", Bangle.swipeHandler); + delete Bangle.swipeHandler; +} +if (Bangle.touchandler) { + Bangle.removeListener("touch", Bangle.touchHandler); + delete Bangle.touchHandler; +} +function b() { + try{Bangle.buzz(20);}catch(e){} +} +if (!mode) return; +else if (mode=="updown") { + Bangle.btnWatches = [ + setWatch(function() { b();cb(-1); }, BTN1, {repeat:1}), + setWatch(function() { b();cb(1); }, BTN3, {repeat:1}), + setWatch(function() { b();cb(); }, BTN2, {repeat:1}) + ]; +} else if (mode=="leftright") { + Bangle.btnWatches = [ + setWatch(function() { b();cb(-1); }, BTN1, {repeat:1}), + setWatch(function() { b();cb(1); }, BTN3, {repeat:1}), + setWatch(function() { b();cb(); }, BTN2, {repeat:1}) + ]; + Bangle.swipeHandler = d => {b();cb(d);}; + Bangle.on("swipe", Bangle.swipeHandler); + Bangle.touchHandler = d => {b();cb();}; + Bangle.on("touch", Bangle.touchHandler); +} else + throw new Error("Unknown UI mode"); +};\n`; +} // Append *.boot.js files require('Storage').list(/\.boot\.js/).forEach(bootFile=>{ boot += "//"+bootFile+"\n"+require('Storage').read(bootFile)+"\n"; diff --git a/apps/launch/ChangeLog b/apps/launch/ChangeLog index 8be4ef463..b56c9f6bb 100644 --- a/apps/launch/ChangeLog +++ b/apps/launch/ChangeLog @@ -3,3 +3,4 @@ 0.03: Allow scrolling to wrap around (fix #382) 0.04: Now displays widgets 0.05: Use g.theme for colours +0.06: Use Bangle.setUI for buttons diff --git a/apps/launch/app.js b/apps/launch/app.js index 0d9d0b004..ab1a89fc0 100644 --- a/apps/launch/app.js +++ b/apps/launch/app.js @@ -43,25 +43,22 @@ function drawMenu() { } g.clear(); drawMenu(); -setWatch(function() { - selected--; - if (selected<0) selected = apps.length-1; - drawMenu(); -}, BTN1, {repeat:true}); -setWatch(function() { - selected++; - if (selected>=apps.length) selected = 0; - drawMenu(); -}, BTN3, {repeat:true}); -setWatch(function() { // run - if (!apps[selected].src) return; - if (require("Storage").read(apps[selected].src)===undefined) { - E.showMessage("App Source\nNot found"); - setTimeout(drawMenu, 2000); +Bangle.setUI("updown",dir=>{ + if (dir) { + selected += dir; + if (selected<0) selected = apps.length-1; + if (selected>=apps.length) selected = 0; + drawMenu(); } else { - E.showMessage("Loading..."); - load(apps[selected].src); + if (!apps[selected].src) return; + if (require("Storage").read(apps[selected].src)===undefined) { + E.showMessage("App Source\nNot found"); + setTimeout(drawMenu, 2000); + } else { + E.showMessage("Loading..."); + load(apps[selected].src); + } } -}, BTN2, {repeat:true,edge:"falling"}); +}); Bangle.loadWidgets(); Bangle.drawWidgets();