mirror of https://github.com/espruino/BangleApps
dtlaunch: add global dtlaunch object
The global dtlaunch object contains function and information to restore the page between instances of dtlaunch.pull/3642/head
parent
7d28e12a38
commit
60089275bc
|
@ -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*4+3, 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
|
||||
}
|
||||
|
@ -102,13 +106,14 @@
|
|||
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 = function(page) {
|
||||
// Function for persisting the active page when leaving dtlaunch.
|
||||
if (page===undefined) {return this.page||0;}
|
||||
|
||||
|
@ -121,7 +126,7 @@
|
|||
|
||||
this.page = page;
|
||||
};
|
||||
Bangle.dtHandlePagePersist(page);
|
||||
dtlaunch.handlePagePersist(page);
|
||||
}
|
||||
|
||||
let swipeListenerDt = function(dirLeftRight, dirUpDown){
|
||||
|
@ -160,7 +165,7 @@
|
|||
drawIcon(page,selected,false);
|
||||
} else {
|
||||
buzzLong();
|
||||
Bangle.dtHandlePagePersist(page);
|
||||
dtlaunch.handlePagePersist(page);
|
||||
load(apps[page*4+i].src);
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +188,7 @@
|
|||
touch : touchListenerDt,
|
||||
remove : ()=>{
|
||||
if (timeoutToClock) {clearTimeout(timeoutToClock);}
|
||||
Bangle.dtHandlePagePersist(page);
|
||||
dtlaunch.handlePagePersist(page);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue