Skip to content

Commit

Permalink
dtlaunch: remember page becomes a setting
Browse files Browse the repository at this point in the history
  • Loading branch information
thyttan committed Nov 11, 2024
1 parent c08b81d commit f47694f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/dtlaunch/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ when moving pages. Add caching for faster startups.
0.24: Add buzz-on-interaction setting
0.25: Minor code improvements
0.26: Bangle 2: Postpone loading icons that are not needed initially.
0.27: Bangle 2: Remember and present the last open page between instances of dtlaunch.
0.27: Bangle 2: Add setting to remember and present the last open page between instances of dtlaunch.
18 changes: 12 additions & 6 deletions apps/dtlaunch/app-b2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
swipeExit: false,
timeOut: "Off",
interactionBuzz: false,
rememberPage: false,
}, require('Storage').readJSON("dtlaunch.json", true) || {});

let s = require("Storage");
Expand All @@ -33,12 +34,17 @@
s.writeJSON("launch.cache.json", launchCache);
}
let apps = launchCache.apps;
let page = (global.dtlaunch&&dtlaunch.handlePagePersist()) ??
(parseInt(s.read("dtlaunch.page")) ?? 0);
let page = 0;
let initPageAppZeroth = 0;
let initPageAppLast = 3;
if (settings.rememberPage) {
page = (global.dtlaunch&&dtlaunch.handlePagePersist()) ??
(parseInt(s.read("dtlaunch.page")) ?? 0);
initPageAppZeroth = page*4;
initPageAppLast = (page*4+3<apps.length-1)?page*4+3:apps.length-1;//Math.min(page*4+3, apps.length-1); // FIXME:What is fastest?
}

const INIT_PAGE_APP_ZEROTH = page*4;
const INIT_PAGE_APP_LAST = (page*4+3<apps.length-1)?page*4+3:apps.length-1;//Math.min(page*4+3, apps.length-1); // FIXME:What is fastest?
for (let i = INIT_PAGE_APP_ZEROTH; i <= INIT_PAGE_APP_LAST; i++) { // Initially only load icons for the current page.
for (let i = initPageAppZeroth; i <= initPageAppLast; 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 @@ -106,7 +112,7 @@
drawPage(page);

for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
if (i >= INIT_PAGE_APP_ZEROTH && i <= INIT_PAGE_APP_LAST) continue;
if (i >= initPageAppZeroth && i <= initPageAppLast) continue;
if (apps[i].icon)
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
}
Expand Down
8 changes: 8 additions & 0 deletions apps/dtlaunch/settings-b2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
swipeExit: false,
timeOut: "Off",
interactionBuzz: false,
rememberPage: false,
}, require('Storage').readJSON(FILE, true) || {});

function writeSettings() {
Expand Down Expand Up @@ -64,5 +65,12 @@
writeSettings();
}
},
/*LANG*/'Remember Page': {
value: settings.rememberPage,
onchange: v => {
settings.rememberPage = v;
writeSettings();
}
},
});
})

0 comments on commit f47694f

Please sign in to comment.