Skip to content

Commit d85b831

Browse files
author
thyttan
committed
Merge branch 'dtlaunch' into app-loader
2 parents 40f33f4 + f47694f commit d85b831

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
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: Add setting to remember and present the last open page between instances of dtlaunch.

apps/dtlaunch/app-b2.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
swipeExit: false,
1212
timeOut: "Off",
1313
interactionBuzz: false,
14+
rememberPage: false,
1415
}, require('Storage').readJSON("dtlaunch.json", true) || {});
1516

1617
let s = require("Storage");
@@ -33,22 +34,31 @@
3334
s.writeJSON("launch.cache.json", launchCache);
3435
}
3536
let apps = launchCache.apps;
36-
for (let i = 0; i < 4; i++) { // Initially only load icons for the current page.
37+
let page = 0;
38+
let initPageAppZeroth = 0;
39+
let initPageAppLast = 3;
40+
if (settings.rememberPage) {
41+
page = (global.dtlaunch&&dtlaunch.handlePagePersist()) ??
42+
(parseInt(s.read("dtlaunch.page")) ?? 0);
43+
initPageAppZeroth = page*4;
44+
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?
45+
}
46+
47+
for (let i = initPageAppZeroth; i <= initPageAppLast; i++) { // Initially only load icons for the current page.
3748
if (apps[i].icon)
3849
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
3950
}
4051

4152
let Napps = apps.length;
42-
let Npages = Math.ceil(Napps/4);
53+
let Npages = parseInt(Napps/4+1); //Math.ceil(Napps/4); // FIXME: What is fastest?
4354
let maxPage = Npages-1;
4455
let selected = -1;
4556
//let oldselected = -1;
46-
let page = 0;
4757
const XOFF = 24;
4858
const YOFF = 30;
4959

5060
let drawIcon= function(p,n,selected) {
51-
let x = (n%2)*72+XOFF;
61+
let x = (n%2)*72+XOFF;
5262
let y = n>1?72+YOFF:YOFF;
5363
(selected?g.setColor(g.theme.fgH):g.setColor(g.theme.bg)).fillRect(x+11,y+3,x+60,y+52);
5464
g.clearRect(x+12,y+4,x+59,y+51);
@@ -99,13 +109,32 @@
99109

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

104-
for (let i = 4; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
114+
for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
115+
if (i >= initPageAppZeroth && i <= initPageAppLast) continue;
105116
if (apps[i].icon)
106117
apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area
107118
}
108119

120+
if (!global.dtlaunch) {
121+
global.dtlaunch = {};
122+
dtlaunch.handlePagePersist = function(page) {
123+
// Function for persisting the active page when leaving dtlaunch.
124+
if (page===undefined) {return this.page||0;}
125+
126+
if (!this.killHandler) { // Only register kill listener once.
127+
this.killHandler = () => {
128+
s.write("dtlaunch.page", this.page.toString());
129+
};
130+
E.on("kill", this.killHandler); // This is intentionally left around after fastloading into other apps. I.e. not removed in uiRemove.
131+
}
132+
133+
this.page = page;
134+
};
135+
dtlaunch.handlePagePersist(page);
136+
}
137+
109138
let swipeListenerDt = function(dirLeftRight, dirUpDown){
110139
updateTimeoutToClock();
111140
selected = -1;
@@ -142,6 +171,7 @@
142171
drawIcon(page,selected,false);
143172
} else {
144173
buzzLong();
174+
dtlaunch.handlePagePersist(page);
145175
load(apps[page*4+i].src);
146176
}
147177
}
@@ -162,7 +192,10 @@
162192
back : Bangle.showClock,
163193
swipe : swipeListenerDt,
164194
touch : touchListenerDt,
165-
remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);}
195+
remove : ()=>{
196+
if (timeoutToClock) {clearTimeout(timeoutToClock);}
197+
dtlaunch.handlePagePersist(page);
198+
}
166199
});
167200

168201
// taken from Icon Launcher with minor alterations
@@ -171,10 +204,9 @@
171204
if (settings.timeOut!="Off"){
172205
let time=parseInt(settings.timeOut); //the "s" will be trimmed by the parseInt
173206
if (timeoutToClock) clearTimeout(timeoutToClock);
174-
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
207+
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
175208
}
176209
};
177210
updateTimeoutToClock();
178211

179212
} // 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",

apps/dtlaunch/settings-b2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
swipeExit: false,
99
timeOut: "Off",
1010
interactionBuzz: false,
11+
rememberPage: false,
1112
}, require('Storage').readJSON(FILE, true) || {});
1213

1314
function writeSettings() {
@@ -64,5 +65,12 @@
6465
writeSettings();
6566
}
6667
},
68+
/*LANG*/'Remember Page': {
69+
value: settings.rememberPage,
70+
onchange: v => {
71+
settings.rememberPage = v;
72+
writeSettings();
73+
}
74+
},
6775
});
6876
})

0 commit comments

Comments
 (0)