From 87ca15597c30c22b6e2d854a4c35860fda734941 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Wed, 16 Oct 2024 00:37:03 +0200 Subject: [PATCH 1/6] quicklaunch: do fewer storage interactions --- apps/quicklaunch/app.js | 51 +++++++++++++++++++++++----------------- apps/quicklaunch/boot.js | 16 ++++++------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/apps/quicklaunch/app.js b/apps/quicklaunch/app.js index 8a56d6c44..5cb9f6254 100644 --- a/apps/quicklaunch/app.js +++ b/apps/quicklaunch/app.js @@ -1,31 +1,40 @@ { + const R = Bangle.appRect; + g.clearRect(R); // clear immediately to increase perceived snappiness. + const storage = require("Storage"); let settings = storage.readJSON("quicklaunch.json", true) || {}; + let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature. - let reset = function(name){ - if (!settings[name]) settings[name] = {"name":"(none)"}; - if (!storage.read(settings[name].src)) settings[name] = {"name":"(none)"}; - storage.write("quicklaunch.json", settings); + const draw = () => { + // Draw app hints + g.reset().clearRect(R).setFont("Vector", 11) + .setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2) + .setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2) + .setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2) + .setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y) + .setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2); }; + draw(); // draw asap to increase perceived snappiness. let leaveTrace = function(trace) { if (settings[trace+"app"].name != "") { settings.trace = trace; - storage.writeJSON("quicklaunch.json", settings); } else { trace = trace.substring(0, trace.length-1); } return trace; }; let launchApp = function(trace) { - if (settings[trace+"app"]) { - if (settings[trace+"app"].src){ - if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) reset(trace+"app"); else load(settings[trace+"app"].src); - } + if (settings[trace+"app"] && settings[trace+"app"].src) { + if (settings[trace+"app"].name == "Extension") draw(); + else if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); + else if (!storage.read(settings[trace+"app"].src)) { + E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch"); + settings[trace+"app"] = {"name":"(none)"}; // reset entry. + } else load(settings[trace+"app"].src); } }; - let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature. - let touchHandler = (_,e) => { if (e.type == 2) return; let R = Bangle.appRect; @@ -47,15 +56,22 @@ if (e.b == 0 && !timeoutToClock) updateTimeoutToClock(); }; + let saveAndClear = ()=> { + storage.writeJSON("quicklaunch.json", settings); + E.removeListener("kill", saveAndClear); + if (timeoutToClock) clearTimeout(timeoutToClock); // Compatibility with Fastload Utils. + } + Bangle.setUI({ mode: "custom", touch: touchHandler, swipe : swipeHandler, drag : onLongTouchDoPause, - remove: ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} // Compatibility with Fastload Utils. + remove: saveAndClear }); - g.clearRect(Bangle.appRect); + E.on("kill", saveAndClear) + "Bangle.loadWidgets()"; // Hack: Fool Fastload Utils that we call Bangle.loadWidgets(). This way we get the fastest possibe loading in whichever environment we find ourselves. // taken from Icon Launcher with some alterations @@ -67,13 +83,4 @@ }; updateTimeoutToClock(); - let R = Bangle.appRect; - - // Draw app hints - g.setFont("Vector", 11) - .setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2) - .setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2) - .setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2) - .setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y) - .setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2); } diff --git a/apps/quicklaunch/boot.js b/apps/quicklaunch/boot.js index 99a6f7175..960c136dc 100644 --- a/apps/quicklaunch/boot.js +++ b/apps/quicklaunch/boot.js @@ -2,12 +2,6 @@ const storage = require("Storage"); let settings = storage.readJSON("quicklaunch.json", true) || {}; - let reset = function(name){ - if (!settings[name]) settings[name] = {"name":"(none)"}; - if (!storage.read(settings[name].src)) settings[name] = {"name":"(none)"}; - storage.write("quicklaunch.json", settings); - }; - let leaveTrace = function(trace) { settings.trace = trace; storage.writeJSON("quicklaunch.json", settings); @@ -15,8 +9,14 @@ }; let launchApp = function(trace) { - if (settings[trace+"app"].src){ - if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) reset(trace+"app"); else load(settings[trace+"app"].src); + if (settings[trace+"app"].src){ + if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); + else if (!storage.read(settings[trace+"app"].src)) { + E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch"); + settings[trace+"app"] = {"name":"(none)"}; // reset entry. + storage.write("quicklaunch.json", settings); + setTimeout(load, 2000); + } else load(settings[trace+"app"].src); } } From b1477a0f8fd63618c3dbc401058fa4baed9a6493 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 28 Oct 2024 23:14:25 +0100 Subject: [PATCH 2/6] quicklaunch: load foreground app before quicklaunch --- apps/quicklaunch/boot.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/quicklaunch/boot.js b/apps/quicklaunch/boot.js index 960c136dc..5277417ce 100644 --- a/apps/quicklaunch/boot.js +++ b/apps/quicklaunch/boot.js @@ -1,4 +1,5 @@ { +setTimeout(() => { // wrap in zero ms timeout so the foreground app loads first. const storage = require("Storage"); let settings = storage.readJSON("quicklaunch.json", true) || {}; @@ -40,4 +41,5 @@ if (ud == 1) trace = leaveTrace("d"); // d=down. launchApp(trace); }); +}, 0); } From e8ef71e410980fc05d136bda224344b65d363c3f Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Mon, 28 Oct 2024 23:43:13 +0100 Subject: [PATCH 3/6] quicklaunch: bump version --- apps/quicklaunch/ChangeLog | 8 +++----- apps/quicklaunch/metadata.json | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/quicklaunch/ChangeLog b/apps/quicklaunch/ChangeLog index 383e6ee2c..54c83c8ae 100644 --- a/apps/quicklaunch/ChangeLog +++ b/apps/quicklaunch/ChangeLog @@ -7,12 +7,10 @@ 0.07: Revert version 0.06. This version is the same as 0.05. 0.08: Respect appRect on touch events 0.09: Do not react if clkinfo is focused -0.10: Extend the functionality via a quicklaunch.app.js file that can be launched - with quicklaunch itself. +0.10: Extend the functionality via a quicklaunch.app.js file that can be launched with quicklaunch itself. 0.11: Add hints to the extension app. Tweak remove function. -0.12: Stackable extension screens. After updating, please visit the quicklaunch - settings page to prompt an automatic update of the quicklaunch.json settings file with - new key names. +0.12: Stackable extension screens. After updating, please visit the quicklaunch settings page to prompt an automatic update of the quicklaunch.json settings file with new key names. 0.13: Touch and hold to pause the timeout to clock temporarily. 0.14: Extension: Don't go down a path if nothing waits at the end. Revisit the current intersection instead. 0.15: Extension: Compatibility with "Fastload Utils" app history feature. +0.16: Snappier. Fewer storage interactions. Set up after the foreground app has loaded in. diff --git a/apps/quicklaunch/metadata.json b/apps/quicklaunch/metadata.json index 5fd06ba95..15c40dfdc 100644 --- a/apps/quicklaunch/metadata.json +++ b/apps/quicklaunch/metadata.json @@ -2,7 +2,7 @@ "id": "quicklaunch", "name": "Quick Launch", "icon": "app.png", - "version": "0.15", + "version": "0.16", "description": "Tap or swipe left/right/up/down on your clock face to launch up to five apps of your choice. Configurations can be accessed through Settings->Apps.", "type": "bootloader", "tags": "tools, system", From ac7ed7dc906d99baad0701b90705ae0c3698af4e Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Wed, 13 Nov 2024 21:56:05 +0100 Subject: [PATCH 4/6] quicklaunch: undo timeout, load settings on demand --- apps/quicklaunch/boot.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/quicklaunch/boot.js b/apps/quicklaunch/boot.js index 5277417ce..5c4f9b88c 100644 --- a/apps/quicklaunch/boot.js +++ b/apps/quicklaunch/boot.js @@ -1,15 +1,18 @@ { -setTimeout(() => { // wrap in zero ms timeout so the foreground app loads first. const storage = require("Storage"); - let settings = storage.readJSON("quicklaunch.json", true) || {}; + let settings; let leaveTrace = function(trace) { + if (!settings) settings = storage.readJSON("quicklaunch.json", true) || {}; + settings.trace = trace; storage.writeJSON("quicklaunch.json", settings); return trace; }; let launchApp = function(trace) { + if (!settings) settings = storage.readJSON("quicklaunch.json", true) || {}; + if (settings[trace+"app"].src){ if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) { @@ -41,5 +44,4 @@ setTimeout(() => { // wrap in zero ms timeout so the foreground app loads first. if (ud == 1) trace = leaveTrace("d"); // d=down. launchApp(trace); }); -}, 0); } From 6195b876640034c64e12aa221f47e72e1eb455a1 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Wed, 13 Nov 2024 22:05:15 +0100 Subject: [PATCH 5/6] quicklaunch: easier to read if-else --- apps/quicklaunch/boot.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/quicklaunch/boot.js b/apps/quicklaunch/boot.js index 5c4f9b88c..5c99e86f9 100644 --- a/apps/quicklaunch/boot.js +++ b/apps/quicklaunch/boot.js @@ -13,16 +13,17 @@ let launchApp = function(trace) { if (!settings) settings = storage.readJSON("quicklaunch.json", true) || {}; - if (settings[trace+"app"].src){ - if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); - else if (!storage.read(settings[trace+"app"].src)) { - E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch"); - settings[trace+"app"] = {"name":"(none)"}; // reset entry. - storage.write("quicklaunch.json", settings); - setTimeout(load, 2000); - } else load(settings[trace+"app"].src); + if (settings[trace+"app"].src) { + if (settings[trace+"app"].name == "Show Launcher") { + Bangle.showLauncher(); + } else if (!storage.read(settings[trace+"app"].src)) { + E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch"); + settings[trace+"app"] = {"name":"(none)"}; // reset entry. + storage.write("quicklaunch.json", settings); + setTimeout(load, 2000); + } else {load(settings[trace+"app"].src);} } - } + }; let trace; From 4688b933abc02cbd4dd04676d1cbb2bb72f62c21 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Wed, 13 Nov 2024 22:11:32 +0100 Subject: [PATCH 6/6] quicklaunch: update ChangeLog --- apps/quicklaunch/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/quicklaunch/ChangeLog b/apps/quicklaunch/ChangeLog index 54c83c8ae..afd110efb 100644 --- a/apps/quicklaunch/ChangeLog +++ b/apps/quicklaunch/ChangeLog @@ -13,4 +13,4 @@ 0.13: Touch and hold to pause the timeout to clock temporarily. 0.14: Extension: Don't go down a path if nothing waits at the end. Revisit the current intersection instead. 0.15: Extension: Compatibility with "Fastload Utils" app history feature. -0.16: Snappier. Fewer storage interactions. Set up after the foreground app has loaded in. +0.16: Snappier. Fewer storage interactions.