Skip to content

Commit de28353

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 61d03cb commit de28353

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

apps/dtlaunch/app-b2.js

Lines changed: 19 additions & 14 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*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.
3842
if (apps[i].icon)
3943
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
4044
}
@@ -102,26 +106,27 @@
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 = (page) => {
112117
// 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;}
114119

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());
118123
};
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.
120125
}
121126

122-
this.page = page;
127+
dtlaunch.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

0 commit comments

Comments
 (0)