Skip to content

Commit

Permalink
dtlaunch: add global dtlaunch object
Browse files Browse the repository at this point in the history
The global dtlaunch object contains function and information to restore
the page between instances of dtlaunch.
  • Loading branch information
thyttan committed Nov 7, 2024
1 parent 61d03cb commit de28353
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions apps/dtlaunch/app-b2.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
s.writeJSON("launch.cache.json", launchCache);
}
let apps = launchCache.apps;
let page = (Bangle.dtHandlePagePersist&&Bangle.dtHandlePagePersist()) ?? (parseInt(s.read("dtlaunch.page")) ?? 0);
for (let i = page*4; i < Math.min(page*4+4, apps.length); i++) { // Initially only load icons for the current page.
let page = (global.dtlaunch&&dtlaunch.HandlePagePersist()) ??
(parseInt(s.read("dtlaunch.page")) ?? 0);

const INIT_PAGE_APP_ZEROTH = page*4;
const INIT_PAGE_APP_LAST = Math.min(page*5-1, apps.length-1)
for (let i = INIT_PAGE_APP_ZEROTH; i <= INIT_PAGE_APP_LAST; i++) { // Initially only load icons for the current page.
if (apps[i].icon)
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
}
Expand Down Expand Up @@ -102,26 +106,27 @@
drawPage(page);

for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
if (i >= page*4 && i < Math.min(page*4+4, apps.length)) continue;
if (i >= INIT_PAGE_APP_ZEROTH && i <= INIT_PAGE_APP_LAST) continue;
if (apps[i].icon)
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
}

if (!Bangle.dtHandlePagePersist) {
Bangle.dtHandlePagePersist = (page) => {
if (!global.dtlaunch) {
global.dtlaunch = {};
dtlaunch.HandlePagePersist = (page) => {
// Function for persisting the active page when leaving dtlaunch.
if (page===undefined) {return this.page||0;}
if (page===undefined) {return dtlaunch.page||0;}

if (!this.killHandler) { // Only register kill listener once.
this.killHandler = () => {
s.write("dtlaunch.page", this.page.toString());
if (!dtlaunch.killHandler) { // Only register kill listener once.
dtlaunch.killHandler = () => {
s.write("dtlaunch.page", dtlaunch.page.toString());
};
E.on("kill", this.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove.
E.on("kill", dtlaunch.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove.
}

this.page = page;
dtlaunch.page = page;
};
Bangle.dtHandlePagePersist(page);
dtlaunch.HandlePagePersist(page);
}

let swipeListenerDt = function(dirLeftRight, dirUpDown){
Expand Down Expand Up @@ -160,7 +165,7 @@
drawIcon(page,selected,false);
} else {
buzzLong();
Bangle.dtHandlePagePersist(page);
dtlaunch.HandlePagePersist(page);
load(apps[page*4+i].src);
}
}
Expand All @@ -183,7 +188,7 @@
touch : touchListenerDt,
remove : ()=>{
if (timeoutToClock) {clearTimeout(timeoutToClock);}
Bangle.dtHandlePagePersist(page);
dtlaunch.HandlePagePersist(page);
}
});

Expand Down

0 comments on commit de28353

Please sign in to comment.