|
33 | 33 | s.writeJSON("launch.cache.json", launchCache); |
34 | 34 | } |
35 | 35 | let apps = launchCache.apps; |
36 | | - for (let i = 0; i < 4; i++) { // Initially only load icons for the current page. |
| 36 | + let page = (global.dtlaunch&&dtlaunch.HandlePagePersist()) ?? |
| 37 | + (parseInt(s.read("dtlaunch.page")) ?? 0); |
| 38 | + |
| 39 | + const INIT_PAGE_APP_ZEROTH = page*4; |
| 40 | + const INIT_PAGE_APP_LAST = Math.min(page*5-1, apps.length-1) |
| 41 | + for (let i = INIT_PAGE_APP_ZEROTH; i <= INIT_PAGE_APP_LAST; i++) { // Initially only load icons for the current page. |
37 | 42 | if (apps[i].icon) |
38 | 43 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
39 | 44 | } |
|
43 | 48 | let maxPage = Npages-1; |
44 | 49 | let selected = -1; |
45 | 50 | //let oldselected = -1; |
46 | | - let page = 0; |
47 | 51 | const XOFF = 24; |
48 | 52 | const YOFF = 30; |
49 | 53 |
|
|
99 | 103 |
|
100 | 104 | Bangle.drawWidgets(); // To immediately update widget field to follow current theme - remove leftovers if previous app set custom theme. |
101 | 105 | Bangle.loadWidgets(); |
102 | | - drawPage(0); |
| 106 | + drawPage(page); |
103 | 107 |
|
104 | | - for (let i = 4; i < apps.length; i++) { // Load the rest of the app icons that were not initially. |
| 108 | + for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially. |
| 109 | + if (i >= INIT_PAGE_APP_ZEROTH && i <= INIT_PAGE_APP_LAST) continue; |
105 | 110 | if (apps[i].icon) |
106 | 111 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
107 | 112 | } |
108 | 113 |
|
| 114 | + if (!global.dtlaunch) { |
| 115 | + global.dtlaunch = {}; |
| 116 | + dtlaunch.HandlePagePersist = (page) => { |
| 117 | + // Function for persisting the active page when leaving dtlaunch. |
| 118 | + if (page===undefined) {return dtlaunch.page||0;} |
| 119 | + |
| 120 | + if (!dtlaunch.killHandler) { // Only register kill listener once. |
| 121 | + dtlaunch.killHandler = () => { |
| 122 | + s.write("dtlaunch.page", dtlaunch.page.toString()); |
| 123 | + }; |
| 124 | + E.on("kill", dtlaunch.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove. |
| 125 | + } |
| 126 | + |
| 127 | + dtlaunch.page = page; |
| 128 | + }; |
| 129 | + dtlaunch.HandlePagePersist(page); |
| 130 | + } |
| 131 | + |
109 | 132 | let swipeListenerDt = function(dirLeftRight, dirUpDown){ |
110 | 133 | updateTimeoutToClock(); |
111 | 134 | selected = -1; |
|
142 | 165 | drawIcon(page,selected,false); |
143 | 166 | } else { |
144 | 167 | buzzLong(); |
| 168 | + dtlaunch.HandlePagePersist(page); |
145 | 169 | load(apps[page*4+i].src); |
146 | 170 | } |
147 | 171 | } |
|
162 | 186 | back : Bangle.showClock, |
163 | 187 | swipe : swipeListenerDt, |
164 | 188 | touch : touchListenerDt, |
165 | | - remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} |
| 189 | + remove : ()=>{ |
| 190 | + if (timeoutToClock) {clearTimeout(timeoutToClock);} |
| 191 | + dtlaunch.HandlePagePersist(page); |
| 192 | + } |
166 | 193 | }); |
167 | 194 |
|
168 | 195 | // taken from Icon Launcher with minor alterations |
|
177 | 204 | updateTimeoutToClock(); |
178 | 205 |
|
179 | 206 | } // end of app scope |
180 | | - |
|
0 commit comments