Skip to content

Commit f4875f4

Browse files
author
thyttan
committed
dtlaunch: add global dtlaunch object
The global dtlaunch object contains function and information to restore the page between instances of dtlaunch.
1 parent 991a9b8 commit f4875f4

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

apps/dtlaunch/app-b2.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
s.writeJSON("launch.cache.json", launchCache);
3434
}
3535
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*4+3, 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.
3842
if (apps[i].icon)
3943
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
4044
}
@@ -48,7 +52,7 @@
4852
const YOFF = 30;
4953

5054
let drawIcon= function(p,n,selected) {
51-
let x = (n%2)*72+XOFF;
55+
let x = (n%2)*72+XOFF;
5256
let y = n>1?72+YOFF:YOFF;
5357
(selected?g.setColor(g.theme.fgH):g.setColor(g.theme.bg)).fillRect(x+11,y+3,x+60,y+52);
5458
g.clearRect(x+12,y+4,x+59,y+51);
@@ -102,13 +106,14 @@
102106
drawPage(page);
103107

104108
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;
106110
if (apps[i].icon)
107111
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
108112
}
109113

110-
if (!Bangle.dtHandlePagePersist) {
111-
Bangle.dtHandlePagePersist = (page) => {
114+
if (!global.dtlaunch) {
115+
global.dtlaunch = {};
116+
dtlaunch.handlePagePersist = function(page) {
112117
// Function for persisting the active page when leaving dtlaunch.
113118
if (page===undefined) {return this.page||0;}
114119

@@ -121,7 +126,7 @@
121126

122127
this.page = page;
123128
};
124-
Bangle.dtHandlePagePersist(page);
129+
dtlaunch.handlePagePersist(page);
125130
}
126131

127132
let swipeListenerDt = function(dirLeftRight, dirUpDown){
@@ -160,7 +165,7 @@
160165
drawIcon(page,selected,false);
161166
} else {
162167
buzzLong();
163-
Bangle.dtHandlePagePersist(page);
168+
dtlaunch.handlePagePersist(page);
164169
load(apps[page*4+i].src);
165170
}
166171
}
@@ -183,7 +188,7 @@
183188
touch : touchListenerDt,
184189
remove : ()=>{
185190
if (timeoutToClock) {clearTimeout(timeoutToClock);}
186-
Bangle.dtHandlePagePersist(page);
191+
dtlaunch.handlePagePersist(page);
187192
}
188193
});
189194

@@ -193,7 +198,7 @@
193198
if (settings.timeOut!="Off"){
194199
let time=parseInt(settings.timeOut); //the "s" will be trimmed by the parseInt
195200
if (timeoutToClock) clearTimeout(timeoutToClock);
196-
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
201+
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
197202
}
198203
};
199204
updateTimeoutToClock();

0 commit comments

Comments
 (0)