Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dtlaunch: remember page between dtlaunch instances #3642

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/dtlaunch/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +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: Add setting to remember and present the last open page between instances of dtlaunch.
48 changes: 40 additions & 8 deletions apps/dtlaunch/app-b2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ // must be inside our own scope here so that when we are unloaded everything disappears

Check failure on line 1 in apps/dtlaunch/app-b2.js

View workflow job for this annotation

GitHub Actions / build

App dtlaunch's dtlaunch.app.js is a JS file but isn't valid JS

/* Desktop launcher
*
Expand All @@ -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,7 +34,17 @@
s.writeJSON("launch.cache.json", launchCache);
}
let apps = launchCache.apps;
for (let i = 0; i < 4; i++) { // Initially only load icons for the current page.
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 = Math.min(page*4+3, apps.length-1);
}

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 All @@ -43,12 +54,11 @@
let maxPage = Npages-1;
let selected = -1;
//let oldselected = -1;
let page = 0;
const XOFF = 24;
const YOFF = 30;

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

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

for (let i = 4; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
for (let i = 0; i < apps.length; i++) { // Load the rest of the app icons that were not initially.
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
}

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;}
bobrippling marked this conversation as resolved.
Show resolved Hide resolved

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

this.page = page;
};
dtlaunch.handlePagePersist(page);
}

let swipeListenerDt = function(dirLeftRight, dirUpDown){
updateTimeoutToClock();
selected = -1;
Expand Down Expand Up @@ -142,6 +171,7 @@
drawIcon(page,selected,false);
} else {
buzzLong();
dtlaunch.handlePagePersist(page);
load(apps[page*4+i].src);
}
}
Expand All @@ -162,7 +192,10 @@
back : Bangle.showClock,
swipe : swipeListenerDt,
touch : touchListenerDt,
remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);}
remove : ()=>{
if (timeoutToClock) {clearTimeout(timeoutToClock);}
dtlaunch.handlePagePersist(page);
}
});

// taken from Icon Launcher with minor alterations
Expand All @@ -171,10 +204,9 @@
if (settings.timeOut!="Off"){
let time=parseInt(settings.timeOut); //the "s" will be trimmed by the parseInt
if (timeoutToClock) clearTimeout(timeoutToClock);
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
timeoutToClock = setTimeout(Bangle.showClock,time*1000);
}
};
updateTimeoutToClock();

} // end of app scope

2 changes: 1 addition & 1 deletion apps/dtlaunch/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dtlaunch",
"name": "Desktop Launcher",
"version": "0.26",
"version": "0.27",
"description": "Desktop style App Launcher with six (four for Bangle 2) apps per page - fast access if you have lots of apps installed.",
"screenshots": [{"url":"shot1.png"},{"url":"shot2.png"},{"url":"shot3.png"}],
"icon": "icon.png",
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();
}
},
});
})
Loading