From 9b140eb8a2b6f33a1d13d1035dc1b51550fd74f4 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.comā©> Date: Tue, 5 Nov 2024 16:13:17 +0100 Subject: [PATCH] dtlaunch: remember page between dtlaunch instances --- apps/dtlaunch/ChangeLog | 1 + apps/dtlaunch/app-b2.js | 35 +++++++++++++++++++++++++++++------ apps/dtlaunch/metadata.json | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/dtlaunch/ChangeLog b/apps/dtlaunch/ChangeLog index 585e89ef95..69177e716d 100644 --- a/apps/dtlaunch/ChangeLog +++ b/apps/dtlaunch/ChangeLog @@ -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: Remember and present the last open page between instances of dtlaunch. diff --git a/apps/dtlaunch/app-b2.js b/apps/dtlaunch/app-b2.js index 9da9149808..4c6d58bb59 100644 --- a/apps/dtlaunch/app-b2.js +++ b/apps/dtlaunch/app-b2.js @@ -33,7 +33,10 @@ 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 = (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. if (apps[i].icon) apps[i].icon = s.read(apps[i].icon); // should just be a link to a memory area } @@ -43,7 +46,6 @@ let maxPage = Npages-1; let selected = -1; //let oldselected = -1; - let page = 0; const XOFF = 24; const YOFF = 30; @@ -99,13 +101,31 @@ 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 >= page*4 && i < Math.min(page*4+4, apps.length)) 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) => { + // Function for persisting the active page when leaving dtlaunch. + if (page===undefined) {return this.page||0;} + + 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; + }; + Bangle.dtHandlePagePersist(page); + } + let swipeListenerDt = function(dirLeftRight, dirUpDown){ updateTimeoutToClock(); selected = -1; @@ -142,6 +162,7 @@ drawIcon(page,selected,false); } else { buzzLong(); + Bangle.dtHandlePagePersist(page); load(apps[page*4+i].src); } } @@ -162,7 +183,10 @@ back : Bangle.showClock, swipe : swipeListenerDt, touch : touchListenerDt, - remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} + remove : ()=>{ + if (timeoutToClock) {clearTimeout(timeoutToClock);} + Bangle.dtHandlePagePersist(page); + } }); // taken from Icon Launcher with minor alterations @@ -177,4 +201,3 @@ updateTimeoutToClock(); } // end of app scope - diff --git a/apps/dtlaunch/metadata.json b/apps/dtlaunch/metadata.json index 0f64308293..1ff75b953a 100644 --- a/apps/dtlaunch/metadata.json +++ b/apps/dtlaunch/metadata.json @@ -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",