|
1 | 1 | { |
| 2 | + const R = Bangle.appRect; |
| 3 | + g.clearRect(R); // clear immediately to increase perceived snappiness. |
| 4 | + |
2 | 5 | const storage = require("Storage"); |
3 | 6 | let settings = storage.readJSON("quicklaunch.json", true) || {}; |
| 7 | + let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature. |
4 | 8 |
|
5 | | - let reset = function(name){ |
6 | | - if (!settings[name]) settings[name] = {"name":"(none)"}; |
7 | | - if (!storage.read(settings[name].src)) settings[name] = {"name":"(none)"}; |
8 | | - storage.write("quicklaunch.json", settings); |
| 9 | + const draw = () => { |
| 10 | + // Draw app hints |
| 11 | + g.reset().clearRect(R).setFont("Vector", 11) |
| 12 | + .setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2) |
| 13 | + .setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2) |
| 14 | + .setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2) |
| 15 | + .setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y) |
| 16 | + .setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2); |
9 | 17 | }; |
| 18 | + draw(); // draw asap to increase perceived snappiness. |
10 | 19 |
|
11 | 20 | let leaveTrace = function(trace) { |
12 | 21 | if (settings[trace+"app"].name != "") { |
13 | 22 | settings.trace = trace; |
14 | | - storage.writeJSON("quicklaunch.json", settings); |
15 | 23 | } else { trace = trace.substring(0, trace.length-1); } |
16 | 24 | return trace; |
17 | 25 | }; |
18 | 26 |
|
19 | 27 | let launchApp = function(trace) { |
20 | | - if (settings[trace+"app"]) { |
21 | | - if (settings[trace+"app"].src){ |
22 | | - if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) reset(trace+"app"); else load(settings[trace+"app"].src); |
23 | | - } |
| 28 | + if (settings[trace+"app"] && settings[trace+"app"].src) { |
| 29 | + if (settings[trace+"app"].name == "Extension") draw(); |
| 30 | + else if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); |
| 31 | + else if (!storage.read(settings[trace+"app"].src)) { |
| 32 | + E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch"); |
| 33 | + settings[trace+"app"] = {"name":"(none)"}; // reset entry. |
| 34 | + } else load(settings[trace+"app"].src); |
24 | 35 | } |
25 | 36 | }; |
26 | 37 |
|
27 | | - let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature. |
28 | | - |
29 | 38 | let touchHandler = (_,e) => { |
30 | 39 | if (e.type == 2) return; |
31 | 40 | let R = Bangle.appRect; |
|
47 | 56 | if (e.b == 0 && !timeoutToClock) updateTimeoutToClock(); |
48 | 57 | }; |
49 | 58 |
|
| 59 | + let saveAndClear = ()=> { |
| 60 | + storage.writeJSON("quicklaunch.json", settings); |
| 61 | + E.removeListener("kill", saveAndClear); |
| 62 | + if (timeoutToClock) clearTimeout(timeoutToClock); // Compatibility with Fastload Utils. |
| 63 | + } |
| 64 | + |
50 | 65 | Bangle.setUI({ |
51 | 66 | mode: "custom", |
52 | 67 | touch: touchHandler, |
53 | 68 | swipe : swipeHandler, |
54 | 69 | drag : onLongTouchDoPause, |
55 | | - remove: ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} // Compatibility with Fastload Utils. |
| 70 | + remove: saveAndClear |
56 | 71 | }); |
57 | 72 |
|
58 | | - g.clearRect(Bangle.appRect); |
| 73 | + E.on("kill", saveAndClear) |
| 74 | + |
59 | 75 | "Bangle.loadWidgets()"; // Hack: Fool Fastload Utils that we call Bangle.loadWidgets(). This way we get the fastest possibe loading in whichever environment we find ourselves. |
60 | 76 |
|
61 | 77 | // taken from Icon Launcher with some alterations |
|
67 | 83 | }; |
68 | 84 | updateTimeoutToClock(); |
69 | 85 |
|
70 | | - let R = Bangle.appRect; |
71 | | - |
72 | | - // Draw app hints |
73 | | - g.setFont("Vector", 11) |
74 | | - .setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2) |
75 | | - .setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2) |
76 | | - .setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2) |
77 | | - .setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y) |
78 | | - .setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2); |
79 | 86 | } |
0 commit comments