|
33 | 33 | s.writeJSON("launch.cache.json", launchCache); |
34 | 34 | } |
35 | 35 | let apps = launchCache.apps; |
36 | | - let page = (Bangle.dtHandlePagePersist&&Bangle.dtHandlePagePersist()) ?? (parseInt(s.read("dtlaunch.page")) ?? 0); |
37 | | - for (let i = page*4; i < Math.min(page*4+4, apps.length); 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. |
38 | 42 | if (apps[i].icon) |
39 | 43 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
40 | 44 | } |
|
102 | 106 | drawPage(page); |
103 | 107 |
|
104 | 108 | for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially. |
105 | | - if (i >= page*4 && i < Math.min(page*4+4, apps.length)) continue; |
| 109 | + if (i >= INIT_PAGE_APP_ZEROTH && i <= INIT_PAGE_APP_LAST) continue; |
106 | 110 | if (apps[i].icon) |
107 | 111 | apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area |
108 | 112 | } |
109 | 113 |
|
110 | | - if (!Bangle.dtHandlePagePersist) { |
111 | | - Bangle.dtHandlePagePersist = (page) => { |
| 114 | + if (!global.dtlaunch) { |
| 115 | + global.dtlaunch = {}; |
| 116 | + dtlaunch.HandlePagePersist = (page) => { |
112 | 117 | // Function for persisting the active page when leaving dtlaunch. |
113 | | - if (page===undefined) {return this.page||0;} |
| 118 | + if (page===undefined) {return dtlaunch.page||0;} |
114 | 119 |
|
115 | | - if (!this.killHandler) { // Only register kill listener once. |
116 | | - this.killHandler = () => { |
117 | | - s.write("dtlaunch.page", this.page.toString()); |
| 120 | + if (!dtlaunch.killHandler) { // Only register kill listener once. |
| 121 | + dtlaunch.killHandler = () => { |
| 122 | + s.write("dtlaunch.page", dtlaunch.page.toString()); |
118 | 123 | }; |
119 | | - E.on("kill", this.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove. |
| 124 | + E.on("kill", dtlaunch.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove. |
120 | 125 | } |
121 | 126 |
|
122 | | - this.page = page; |
| 127 | + dtlaunch.page = page; |
123 | 128 | }; |
124 | | - Bangle.dtHandlePagePersist(page); |
| 129 | + dtlaunch.HandlePagePersist(page); |
125 | 130 | } |
126 | 131 |
|
127 | 132 | let swipeListenerDt = function(dirLeftRight, dirUpDown){ |
|
160 | 165 | drawIcon(page,selected,false); |
161 | 166 | } else { |
162 | 167 | buzzLong(); |
163 | | - Bangle.dtHandlePagePersist(page); |
| 168 | + dtlaunch.HandlePagePersist(page); |
164 | 169 | load(apps[page*4+i].src); |
165 | 170 | } |
166 | 171 | } |
|
183 | 188 | touch : touchListenerDt, |
184 | 189 | remove : ()=>{ |
185 | 190 | if (timeoutToClock) {clearTimeout(timeoutToClock);} |
186 | | - Bangle.dtHandlePagePersist(page); |
| 191 | + dtlaunch.HandlePagePersist(page); |
187 | 192 | } |
188 | 193 | }); |
189 | 194 |
|
|
0 commit comments