Skip to content

Commit 61d03cb

Browse files
author
thyttan
committed
dtlaunch: remember page between dtlaunch instances
1 parent 88e4625 commit 61d03cb

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

apps/dtlaunch/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ when moving pages. Add caching for faster startups.
3131
0.24: Add buzz-on-interaction setting
3232
0.25: Minor code improvements
3333
0.26: Bangle 2: Postpone loading icons that are not needed initially.
34+
0.27: Bangle 2: Remember and present the last open page between instances of dtlaunch.

apps/dtlaunch/app-b2.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
s.writeJSON("launch.cache.json", launchCache);
3434
}
3535
let apps = launchCache.apps;
36-
for (let i = 0; i < 4; i++) { // Initially only load icons for the current page.
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.
3738
if (apps[i].icon)
3839
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
3940
}
@@ -43,7 +44,6 @@
4344
let maxPage = Npages-1;
4445
let selected = -1;
4546
//let oldselected = -1;
46-
let page = 0;
4747
const XOFF = 24;
4848
const YOFF = 30;
4949

@@ -99,13 +99,31 @@
9999

100100
Bangle.drawWidgets(); // To immediately update widget field to follow current theme - remove leftovers if previous app set custom theme.
101101
Bangle.loadWidgets();
102-
drawPage(0);
102+
drawPage(page);
103103

104-
for (let i = 4; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
104+
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;
105106
if (apps[i].icon)
106107
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
107108
}
108109

110+
if (!Bangle.dtHandlePagePersist) {
111+
Bangle.dtHandlePagePersist = (page) => {
112+
// Function for persisting the active page when leaving dtlaunch.
113+
if (page===undefined) {return this.page||0;}
114+
115+
if (!this.killHandler) { // Only register kill listener once.
116+
this.killHandler = () => {
117+
s.write("dtlaunch.page", this.page.toString());
118+
};
119+
E.on("kill", this.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove.
120+
}
121+
122+
this.page = page;
123+
};
124+
Bangle.dtHandlePagePersist(page);
125+
}
126+
109127
let swipeListenerDt = function(dirLeftRight, dirUpDown){
110128
updateTimeoutToClock();
111129
selected = -1;
@@ -142,6 +160,7 @@
142160
drawIcon(page,selected,false);
143161
} else {
144162
buzzLong();
163+
Bangle.dtHandlePagePersist(page);
145164
load(apps[page*4+i].src);
146165
}
147166
}
@@ -162,7 +181,10 @@
162181
back : Bangle.showClock,
163182
swipe : swipeListenerDt,
164183
touch : touchListenerDt,
165-
remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);}
184+
remove : ()=>{
185+
if (timeoutToClock) {clearTimeout(timeoutToClock);}
186+
Bangle.dtHandlePagePersist(page);
187+
}
166188
});
167189

168190
// taken from Icon Launcher with minor alterations
@@ -177,4 +199,3 @@
177199
updateTimeoutToClock();
178200

179201
} // end of app scope
180-

apps/dtlaunch/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dtlaunch",
33
"name": "Desktop Launcher",
4-
"version": "0.26",
4+
"version": "0.27",
55
"description": "Desktop style App Launcher with six (four for Bangle 2) apps per page - fast access if you have lots of apps installed.",
66
"screenshots": [{"url":"shot1.png"},{"url":"shot2.png"},{"url":"shot3.png"}],
77
"icon": "icon.png",

0 commit comments

Comments
 (0)