Add 'Bangle.setUI' polyfill and use it from launcher

pull/756/head
Gordon Williams 2021-05-26 20:21:28 +01:00
parent 1dca641ff0
commit 6d1ac3b7c6
5 changed files with 58 additions and 21 deletions

View File

@ -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",

View File

@ -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

View File

@ -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";

View File

@ -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

View File

@ -43,17 +43,13 @@ function drawMenu() {
}
g.clear();
drawMenu();
setWatch(function() {
selected--;
Bangle.setUI("updown",dir=>{
if (dir) {
selected += dir;
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
} else {
if (!apps[selected].src) return;
if (require("Storage").read(apps[selected].src)===undefined) {
E.showMessage("App Source\nNot found");
@ -62,6 +58,7 @@ setWatch(function() { // run
E.showMessage("Loading...");
load(apps[selected].src);
}
}, BTN2, {repeat:true,edge:"falling"});
}
});
Bangle.loadWidgets();
Bangle.drawWidgets();