|
| 1 | + |
| 2 | +let s = require("Storage"); |
| 3 | +let settings = Object.assign( |
| 4 | + {showClocks:false,showLaunchers:false, showWidgets:true},s.readJSON("gridlaunch.settings.json")||{}); |
| 5 | + |
| 6 | +let launchCache = require("launch_utils").cache(settings); |
| 7 | +let apps = launchCache.apps; |
| 8 | +let chunkedApps = []; |
| 9 | + |
| 10 | +for (let i = 0; i < apps.length; i += 3) { |
| 11 | + chunkedApps.push(apps.slice(i, i + 3)); |
| 12 | +} |
| 13 | +if(settings.showWidgets){ |
| 14 | + Bangle.loadWidgets(); |
| 15 | + Bangle.drawWidgets(); |
| 16 | +} |
| 17 | +E.showScroller({ |
| 18 | + h : 70, |
| 19 | + c : chunkedApps.length-1, |
| 20 | + draw : (idx, r) => { |
| 21 | + if (!chunkedApps[idx]) return; |
| 22 | + |
| 23 | + const iconW = 43; |
| 24 | + const third = r.w / 3; |
| 25 | + const x0 = r.x + (third * 0.5) - (iconW / 2); |
| 26 | + const x1 = r.x + (third * 1.5) - (iconW / 2); |
| 27 | + const x2 = r.x + (third * 2.5) - (iconW / 2); |
| 28 | + |
| 29 | + // 2. Strict checks ensure s.read() is only executed if BOTH the app and icon exist |
| 30 | + if (chunkedApps[idx][0] && chunkedApps[idx][0].icon) { |
| 31 | + g.drawImage(s.read(chunkedApps[idx][0].icon), x0, r.y, {scale:0.9}); |
| 32 | + } |
| 33 | + if (chunkedApps[idx][1] && chunkedApps[idx][1].icon) { |
| 34 | + g.drawImage(s.read(chunkedApps[idx][1].icon), x1, r.y+26, {scale:0.9}); |
| 35 | + } |
| 36 | + if (chunkedApps[idx][2] && chunkedApps[idx][2].icon) { |
| 37 | + g.drawImage(s.read(chunkedApps[idx][2].icon), x2, r.y, {scale:0.9}); |
| 38 | + } |
| 39 | + }, |
| 40 | + select : (idx, touch) => { |
| 41 | + let hIdx = 2; |
| 42 | + if(touch.x<g.getWidth()/3*2) hIdx = 1; |
| 43 | + if(touch.x<g.getWidth()/3) hIdx = 0; |
| 44 | + |
| 45 | + if (Bangle.haptic) Bangle.haptic("touch"); |
| 46 | + var app = chunkedApps[idx][hIdx]; |
| 47 | + if (!app) return; |
| 48 | + if (Bangle.haptic) Bangle.haptic("touch"); |
| 49 | + if (!app.src || s.read(app.src)===undefined) { |
| 50 | + E.showScroller(); |
| 51 | + E.showMessage(/*LANG*/"App Source\nNot found"); |
| 52 | + } else { |
| 53 | + require("launch_utils").loadApp(app); |
| 54 | + } |
| 55 | + }, |
| 56 | + back : Bangle.showClock, |
| 57 | +}); |
| 58 | + |
| 59 | + |
0 commit comments