1
0
Fork 0

Merge pull request #2719 from bobrippling/feature/ratchet-cache

Ratchet launch: add caching
master
Gordon Williams 2023-05-04 10:34:42 +01:00 committed by GitHub
commit 7830fb60c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 23 deletions

View File

@ -8,4 +8,5 @@
Add widget for live monitoring of power use
0.07: Convert Yes/No On/Off in settings to checkboxes
0.08: Fix the wrapping of intervals/timeouts with parameters
Fix the widget drawing if widgets are hidden and Bangle.setLCDBrightness is called
Fix the widget drawing if widgets are hidden and Bangle.setLCDBrightness is called
0.09: Cache the app-launch info

View File

@ -2,7 +2,7 @@
"id": "powermanager",
"name": "Power Manager",
"shortName": "Power Manager",
"version": "0.08",
"version": "0.09",
"description": "Allow configuration of warnings and thresholds for battery charging and display.",
"icon": "app.png",
"type": "bootloader",

View File

@ -9,27 +9,38 @@ var blankImage = Graphics.createImage(` `);
var rowHeight = g.getHeight()/3;
// Load apps list
var apps = Storage.list(/\.info$/).map(app=>{
var a=Storage.readJSON(app,1);
return a&&{
name:a.name,
type:a.type,
icon:a.icon ? Storage.read(a.icon) : a.icon,
sortorder:a.sortorder,
src:a.src
};
}).filter(app=>app && (
app.type=="app"
// || (app.type=="clock" && settings.showClocks)
|| !app.type
));
apps.sort((a,b)=>{
var n=(0|a.sortorder)-(0|b.sortorder);
if (n) return n; // do sortorder first
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
return 0;
});
var apps;
var launchCache = s.readJSON("launch.cache.json", true)||{};
var launchHash = require("Storage").hash(/\.info/);
if (launchCache.hash==launchHash) {
apps = launchCache.apps;
} else {
apps = Storage.list(/\.info$/).map(app=>{
var a=Storage.readJSON(app,1);
return a&&{
name:a.name,
type:a.type,
icon:a.icon ? Storage.read(a.icon) : a.icon,
sortorder:a.sortorder,
src:a.src
};
}).filter(app=>app && (
app.type=="app"
// || (app.type=="clock" && settings.showClocks)
|| !app.type
));
apps.sort((a,b)=>{
var n=(0|a.sortorder)-(0|b.sortorder);
if (n) return n; // do sortorder first
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
return 0;
});
launchCache = { apps, hash: launchHash };
s.writeJSON("launch.cache.json", launchCache);
}
// Uncomment for testing in the emulator without apps:
// apps = [