|
11 | 11 | swipeExit: false, |
12 | 12 | timeOut: "Off", |
13 | 13 | interactionBuzz: false, |
| 14 | + rememberPage: false, |
14 | 15 | }, require('Storage').readJSON("dtlaunch.json", true) || {}); |
15 | 16 |
|
16 | 17 | let s = require("Storage"); |
|
33 | 34 | s.writeJSON("launch.cache.json", launchCache); |
34 | 35 | } |
35 | 36 | let apps = launchCache.apps; |
36 | | - for (let i = 0; i < 4; i++) { // Initially only load icons for the current page. |
| 37 | + let page = 0; |
| 38 | + let initPageAppZeroth = 0; |
| 39 | + let initPageAppLast = 3; |
| 40 | + if (settings.rememberPage) { |
| 41 | + page = (global.dtlaunch&&dtlaunch.handlePagePersist()) ?? |
| 42 | + (parseInt(s.read("dtlaunch.page")) ?? 0); |
| 43 | + initPageAppZeroth = page*4; |
| 44 | + initPageAppLast = (page*4+3<apps.length-1)?page*4+3:apps.length-1;//Math.min(page*4+3, apps.length-1); // FIXME:What is fastest? |
| 45 | + } |
| 46 | + |
| 47 | + for (let i = initPageAppZeroth; i <= initPageAppLast; i++) { // Initially only load icons for the current page. |
37 | 48 | if (apps[i].icon) |
38 | 49 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
39 | 50 | } |
40 | 51 |
|
41 | 52 | let Napps = apps.length; |
42 | | - let Npages = Math.ceil(Napps/4); |
| 53 | + let Npages = parseInt(Napps/4+1); //Math.ceil(Napps/4); // FIXME: What is fastest? |
43 | 54 | let maxPage = Npages-1; |
44 | 55 | let selected = -1; |
45 | 56 | //let oldselected = -1; |
46 | | - let page = 0; |
47 | 57 | const XOFF = 24; |
48 | 58 | const YOFF = 30; |
49 | 59 |
|
50 | 60 | let drawIcon= function(p,n,selected) { |
51 | | - let x = (n%2)*72+XOFF; |
| 61 | + let x = (n%2)*72+XOFF; |
52 | 62 | let y = n>1?72+YOFF:YOFF; |
53 | 63 | (selected?g.setColor(g.theme.fgH):g.setColor(g.theme.bg)).fillRect(x+11,y+3,x+60,y+52); |
54 | 64 | g.clearRect(x+12,y+4,x+59,y+51); |
|
99 | 109 |
|
100 | 110 | Bangle.drawWidgets(); // To immediately update widget field to follow current theme - remove leftovers if previous app set custom theme. |
101 | 111 | Bangle.loadWidgets(); |
102 | | - drawPage(0); |
| 112 | + drawPage(page); |
103 | 113 |
|
104 | | - for (let i = 4; i < apps.length; i++) { // Load the rest of the app icons that were not initially. |
| 114 | + for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially. |
| 115 | + if (i >= initPageAppZeroth && i <= initPageAppLast) continue; |
105 | 116 | if (apps[i].icon) |
106 | 117 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
107 | 118 | } |
108 | 119 |
|
| 120 | + if (!global.dtlaunch) { |
| 121 | + global.dtlaunch = {}; |
| 122 | + dtlaunch.handlePagePersist = function(page) { |
| 123 | + // Function for persisting the active page when leaving dtlaunch. |
| 124 | + if (page===undefined) {return this.page||0;} |
| 125 | + |
| 126 | + if (!this.killHandler) { // Only register kill listener once. |
| 127 | + this.killHandler = () => { |
| 128 | + s.write("dtlaunch.page", this.page.toString()); |
| 129 | + }; |
| 130 | + E.on("kill", this.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove. |
| 131 | + } |
| 132 | + |
| 133 | + this.page = page; |
| 134 | + }; |
| 135 | + dtlaunch.handlePagePersist(page); |
| 136 | + } |
| 137 | + |
109 | 138 | let swipeListenerDt = function(dirLeftRight, dirUpDown){ |
110 | 139 | updateTimeoutToClock(); |
111 | 140 | selected = -1; |
|
142 | 171 | drawIcon(page,selected,false); |
143 | 172 | } else { |
144 | 173 | buzzLong(); |
| 174 | + dtlaunch.handlePagePersist(page); |
145 | 175 | load(apps[page*4+i].src); |
146 | 176 | } |
147 | 177 | } |
|
162 | 192 | back : Bangle.showClock, |
163 | 193 | swipe : swipeListenerDt, |
164 | 194 | touch : touchListenerDt, |
165 | | - remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} |
| 195 | + remove : ()=>{ |
| 196 | + if (timeoutToClock) {clearTimeout(timeoutToClock);} |
| 197 | + dtlaunch.handlePagePersist(page); |
| 198 | + } |
166 | 199 | }); |
167 | 200 |
|
168 | 201 | // taken from Icon Launcher with minor alterations |
|
171 | 204 | if (settings.timeOut!="Off"){ |
172 | 205 | let time=parseInt(settings.timeOut); //the "s" will be trimmed by the parseInt |
173 | 206 | if (timeoutToClock) clearTimeout(timeoutToClock); |
174 | | - timeoutToClock = setTimeout(Bangle.showClock,time*1000); |
| 207 | + timeoutToClock = setTimeout(Bangle.showClock,time*1000); |
175 | 208 | } |
176 | 209 | }; |
177 | 210 | updateTimeoutToClock(); |
178 | 211 |
|
179 | 212 | } // end of app scope |
180 | | - |
|
0 commit comments