From 298fbf0d84afe6399a00f00f048fd02369a1dc7d Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 6 Oct 2022 20:06:12 +0200 Subject: [PATCH 1/7] iconlaunch - Directly eval apps instead of loading them --- apps/iconlaunch/app.js | 68 ++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/apps/iconlaunch/app.js b/apps/iconlaunch/app.js index 97f7f0ac1..dee237515 100644 --- a/apps/iconlaunch/app.js +++ b/apps/iconlaunch/app.js @@ -2,14 +2,6 @@ const s = require("Storage"); const settings = s.readJSON("launch.json", true) || { showClocks: true, fullscreen: false,direct:false,oneClickExit:false }; - function returnToClock() { - Bangle.setUI(); - setTimeout(eval,0,s.read(".bootcde")); - } - - if( settings.oneClickExit) - setWatch(returnToClock, BTN1); - if (!settings.fullscreen) { if (!global.WIDGETS) Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -58,7 +50,7 @@ const itemSize = iconSize + whitespace; - function drawItem(itemI, r) { + let drawItem = function(itemI, r) { g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1); let x = 0; for (let i = itemI * appsN; i < appsN * (itemI + 1); i++) { @@ -80,9 +72,9 @@ x += iconSize; } drawText(itemI); - } + }; - function drawItemAuto(i) { + let drawItemAuto = function(i) { var y = idxToY(i); g.reset().setClipRect(R.x, y, R.x2, y + itemSize); drawItem(i, { @@ -92,11 +84,11 @@ h: itemSize }); g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); - } + }; let lastIsDown = false; - function drawText(i) { + let drawText = function(i) { const selectedApp = apps[selectedItem]; const idy = (selectedItem - (selectedItem % 3)) / 3; if (!selectedApp || i != idy) return; @@ -111,14 +103,14 @@ appY + rect.height / 2 ); g.drawString(selectedApp.name, R.w / 2, appY); - } + }; - function selectItem(id, e) { + let selectItem = function(id, e) { const iconN = E.clip(Math.floor((e.x - R.x) / itemSize), 0, appsN - 1); const appId = id * appsN + iconN; if( settings.direct && apps[appId]) { - load(apps[appId].src); + loadApp(apps[appId].src); return; } if (appId == selectedItem && apps[appId]) { @@ -131,17 +123,17 @@ } selectedItem = appId; drawItems(); - } + }; - function idxToY(i) { + let idxToY = function(i) { return i * itemSize + R.y - (scroll & ~1); - } + }; - function YtoIdx(y) { + let YtoIdx = function(y) { return Math.floor((y + (scroll & ~1) - R.y) / itemSize); - } + }; - function drawItems() { + let drawItems = function() { g.reset().clearRect(R.x, R.y, R.x2, R.y2); g.setClipRect(R.x, R.y, R.x2, R.y2); var a = YtoIdx(R.y); @@ -154,14 +146,14 @@ h: itemSize, }); g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); - } + }; drawItems(); g.flip(); const itemsN = Math.ceil(apps.length / appsN); - function onDrag(e){ + let onDrag = function(e){ g.setColor(g.theme.fg); g.setBgColor(g.theme.bg); let dy = e.dy; @@ -206,7 +198,7 @@ } } g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); - } + }; Bangle.setUI({ mode: "custom", @@ -217,4 +209,30 @@ selectItem(i, e); }, }); + + const returnToClock = function() { + loadApp(".bootcde"); + }; + + let loadApp = function(name){ + Bangle.setUI(); + //minimize RAM use during load + apps = []; + delete drawItemAuto; + delete drawText; + delete selectItem; + delete onDrag; + delete drawItems; + delete drawItem; + delete returnToClock; + delete idxToY; + delete YtoIdx; + delete settings; + setTimeout(eval,0,s.read(name)); + return; + }; + + if( settings.oneClickExit){ + setWatch(returnToClock, BTN1); + } } From f586bacbf2cae12464b4533a38304a0100cf78cc Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 6 Oct 2022 20:08:21 +0200 Subject: [PATCH 2/7] iconlaunch - Bump version and changelog --- apps/iconlaunch/ChangeLog | 1 + apps/iconlaunch/metadata.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/iconlaunch/ChangeLog b/apps/iconlaunch/ChangeLog index fcd7c9194..8426673aa 100644 --- a/apps/iconlaunch/ChangeLog +++ b/apps/iconlaunch/ChangeLog @@ -2,3 +2,4 @@ 0.02: implemented "direct launch" and "one click exit" settings 0.03: Use default Bangle formatter for booleans 0.04: Support new fast app switching +0.05: Directly eval apps instead of loading diff --git a/apps/iconlaunch/metadata.json b/apps/iconlaunch/metadata.json index f1c34cf3d..82d2e7578 100644 --- a/apps/iconlaunch/metadata.json +++ b/apps/iconlaunch/metadata.json @@ -2,7 +2,7 @@ "id": "iconlaunch", "name": "Icon Launcher", "shortName" : "Icon launcher", - "version": "0.04", + "version": "0.05", "icon": "app.png", "description": "A launcher inspired by smartphones, with an icon-only scrollable menu.", "tags": "tool,system,launcher", From e893f10663f7fb4058807647a2531271afbd9c45 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 7 Oct 2022 08:23:21 +0200 Subject: [PATCH 3/7] iconlaunch - Also reset button watch --- apps/iconlaunch/app.js | 63 ++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/apps/iconlaunch/app.js b/apps/iconlaunch/app.js index dee237515..8f4b359fe 100644 --- a/apps/iconlaunch/app.js +++ b/apps/iconlaunch/app.js @@ -1,23 +1,21 @@ { const s = require("Storage"); const settings = s.readJSON("launch.json", true) || { showClocks: true, fullscreen: false,direct:false,oneClickExit:false }; - if (!settings.fullscreen) { if (!global.WIDGETS) Bangle.loadWidgets(); Bangle.drawWidgets(); } - var apps = s .list(/\.info$/) .map((app) => { - var a = s.readJSON(app, 1); + var a = s.readJSON(app, 1); return ( a && { - name: a.name, - type: a.type, - icon: a.icon, - sortorder: a.sortorder, - src: a.src, + name: a.name, + type: a.type, + icon: a.icon, + sortorder: a.sortorder, + src: a.src, } ); }) @@ -30,26 +28,21 @@ ); apps.sort((a, b) => { var n = (0 | a.sortorder) - (0 | b.sortorder); - if (n) return n; // do sortorder first + if (n) return n; if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; }); apps.forEach((app) => { - if (app.icon) app.icon = s.read(app.icon); // should just be a link to a memory area + if (app.icon) app.icon = s.read(app.icon); }); - let scroll = 0; let selectedItem = -1; const R = Bangle.appRect; - const iconSize = 48; - const appsN = Math.floor(R.w / iconSize); const whitespace = (R.w - appsN * iconSize) / (appsN + 1); - const itemSize = iconSize + whitespace; - let drawItem = function(itemI, r) { g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1); let x = 0; @@ -57,7 +50,7 @@ if (!apps[i]) break; x += whitespace; if (!apps[i].icon) { - g.setFontAlign(0,0,0).setFont("12x20:2").drawString("?", x + r.x+iconSize/2, r.y + iconSize/2); + g.setFontAlign(0, 0, 0).setFont("12x20:2").drawString("?", x + r.x + iconSize / 2, r.y + iconSize / 2); } else { g.drawImage(apps[i].icon, x + r.x, r.y); } @@ -73,7 +66,6 @@ } drawText(itemI); }; - let drawItemAuto = function(i) { var y = idxToY(i); g.reset().setClipRect(R.x, y, R.x2, y + itemSize); @@ -85,9 +77,7 @@ }); g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); }; - let lastIsDown = false; - let drawText = function(i) { const selectedApp = apps[selectedItem]; const idy = (selectedItem - (selectedItem % 3)) / 3; @@ -104,7 +94,6 @@ ); g.drawString(selectedApp.name, R.w / 2, appY); }; - let selectItem = function(id, e) { const iconN = E.clip(Math.floor((e.x - R.x) / itemSize), 0, appsN - 1); const appId = id * appsN + iconN; @@ -124,15 +113,12 @@ selectedItem = appId; drawItems(); }; - let idxToY = function(i) { return i * itemSize + R.y - (scroll & ~1); }; - let YtoIdx = function(y) { return Math.floor((y + (scroll & ~1) - R.y) / itemSize); }; - let drawItems = function() { g.reset().clearRect(R.x, R.y, R.x2, R.y2); g.setClipRect(R.x, R.y, R.x2, R.y2); @@ -140,20 +126,17 @@ var b = Math.min(YtoIdx(R.y2), 99); for (var i = a; i <= b; i++) drawItem(i, { - x: R.x, - y: idxToY(i), - w: R.w, - h: itemSize, - }); + x: R.x, + y: idxToY(i), + w: R.w, + h: itemSize, + }); g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); }; - drawItems(); g.flip(); - const itemsN = Math.ceil(apps.length / appsN); - - let onDrag = function(e){ + let onDrag = function(e) { g.setColor(g.theme.fg); g.setBgColor(g.theme.bg); let dy = e.dy; @@ -182,7 +165,6 @@ y += itemSize; } } else { - // d>0 g.setClipRect(R.x, R.y, R.x2, R.y + dy); let i = YtoIdx(R.y + dy); let y = idxToY(i); @@ -199,7 +181,6 @@ } g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1); }; - Bangle.setUI({ mode: "custom", drag: onDrag, @@ -209,14 +190,13 @@ selectItem(i, e); }, }); - const returnToClock = function() { loadApp(".bootcde"); }; - - let loadApp = function(name){ + let watch; + let loadApp = function(name) { Bangle.setUI(); - //minimize RAM use during load + if (watch) clearWatch(watch); apps = []; delete drawItemAuto; delete drawText; @@ -228,11 +208,10 @@ delete idxToY; delete YtoIdx; delete settings; - setTimeout(eval,0,s.read(name)); + setTimeout(eval, 0, s.read(name)); return; }; - - if( settings.oneClickExit){ - setWatch(returnToClock, BTN1); + if (settings.oneClickExit) { + watch = setWatch(returnToClock, BTN1); } } From f3118e8fe0063905aa671166ec2928edc30a12be Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 22:09:51 +0200 Subject: [PATCH 4/7] iconlaunch - Adds setting for fast loading apps --- apps/iconlaunch/app.js | 44 ++++++++++++++++++++++--------------- apps/iconlaunch/settings.js | 4 ++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/iconlaunch/app.js b/apps/iconlaunch/app.js index 8f4b359fe..50c55d155 100644 --- a/apps/iconlaunch/app.js +++ b/apps/iconlaunch/app.js @@ -107,7 +107,7 @@ if (!app.src || s.read(app.src) === undefined) { E.showMessage( /*LANG*/ "App Source\nNot found"); } else { - load(app.src); + loadApp(app.src); } } selectedItem = appId; @@ -194,23 +194,31 @@ loadApp(".bootcde"); }; let watch; - let loadApp = function(name) { - Bangle.setUI(); - if (watch) clearWatch(watch); - apps = []; - delete drawItemAuto; - delete drawText; - delete selectItem; - delete onDrag; - delete drawItems; - delete drawItem; - delete returnToClock; - delete idxToY; - delete YtoIdx; - delete settings; - setTimeout(eval, 0, s.read(name)); - return; - }; + let loadApp; + if (settings.fastload){ + loadApp = function(name) { + Bangle.setUI(); + if (watch) clearWatch(watch); + apps = []; + delete drawItemAuto; + delete drawText; + delete selectItem; + delete onDrag; + delete drawItems; + delete drawItem; + delete returnToClock; + delete idxToY; + delete YtoIdx; + delete settings; + setTimeout(eval, 0, s.read(name)); + return; + }; + } else { + loadApp = function(name) { + load(name); + } + } + if (settings.oneClickExit) { watch = setWatch(returnToClock, BTN1); } diff --git a/apps/iconlaunch/settings.js b/apps/iconlaunch/settings.js index bd1a4a597..449a1c096 100644 --- a/apps/iconlaunch/settings.js +++ b/apps/iconlaunch/settings.js @@ -28,6 +28,10 @@ /*LANG*/"One click exit": { value: settings.oneClickExit == true, onchange: (m) => { save("oneClickExit", m) } + }, + /*LANG*/"Fastload": { + value: settings.fastload == true, + onchange: (m) => { save("fastload", m) } } }; E.showMenu(appMenu); From 10e8062a08382b99d71778439bc78a195343872b Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 22:26:09 +0200 Subject: [PATCH 5/7] iconlaunch - Update readme --- apps/iconlaunch/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/iconlaunch/README.md b/apps/iconlaunch/README.md index 0d36fdeb4..0b67494ce 100644 --- a/apps/iconlaunch/README.md +++ b/apps/iconlaunch/README.md @@ -10,3 +10,7 @@ This launcher shows 9 apps per screen, making it much faster to navigate versus ## Technical note The app uses `E.showScroller`'s code in the app but not the function itself because `E.showScroller` doesn't report the position of a press to the select function. + +### Fastload option + +Fastload clears up the memory used by the launcher and directly evals the code of the app to load. This means if widgets are loaded (fullscreen option) it is possible that widgets stay loaded in apps not expecting that and the widgets may draw over the app. From 58308103c115f79aa4e173e462472dcb76ac265c Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 22:26:33 +0200 Subject: [PATCH 6/7] iconlaunch - Remove redundant check --- apps/iconlaunch/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/iconlaunch/app.js b/apps/iconlaunch/app.js index 50c55d155..fd58176db 100644 --- a/apps/iconlaunch/app.js +++ b/apps/iconlaunch/app.js @@ -2,7 +2,7 @@ const s = require("Storage"); const settings = s.readJSON("launch.json", true) || { showClocks: true, fullscreen: false,direct:false,oneClickExit:false }; if (!settings.fullscreen) { - if (!global.WIDGETS) Bangle.loadWidgets(); + Bangle.loadWidgets(); Bangle.drawWidgets(); } var apps = s From 145bde8240290a0075f7052da215fcf88abc1a95 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 13 Oct 2022 22:41:20 +0200 Subject: [PATCH 7/7] iconlaunch - Modify changelog --- apps/iconlaunch/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/iconlaunch/ChangeLog b/apps/iconlaunch/ChangeLog index 8426673aa..858d13b80 100644 --- a/apps/iconlaunch/ChangeLog +++ b/apps/iconlaunch/ChangeLog @@ -2,4 +2,4 @@ 0.02: implemented "direct launch" and "one click exit" settings 0.03: Use default Bangle formatter for booleans 0.04: Support new fast app switching -0.05: Directly eval apps instead of loading +0.05: Allow to directly eval apps instead of loading