From 95f9aa691bd778f3eb64ef921d17e89cca0f8df9 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 31 May 2026 12:35:24 +0200 Subject: [PATCH] launch_utils: break out widgets check to separate method The method takes an array of apps to check, then updates their entries in `launch.cache.json` and returns that updated launcher cache. The following example shows how this can be used to update widget info for all apps at once. ``` var launchCache = require("launch_utils").cache({showClocks:true,showLaunchers:true}); launchCache = require("launch_utils").cacheWidgetsCheck(launchCache.apps); ``` --- modules/launch_utils.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/launch_utils.js b/modules/launch_utils.js index b045272c595..6c5236262ab 100644 --- a/modules/launch_utils.js +++ b/modules/launch_utils.js @@ -51,18 +51,7 @@ exports.cache = function(settings) { /** Call with app object from .cache() */ exports.loadApp = function(app) { if (!app.src) return E.showMessage(/*LANG*/ "App Source\nNot found"); // sanity check - if (app.wid===undefined) { // If we hadn't stored whether the app uses widgets before, check now - let s = require("Storage"); - let src = s.read(app.src) - app.wid = (src!==undefined)&&src.includes("Bangle.loadWidgets"); - // Now update the launch cache to save having to do this again - let launchCache = s.readJSON("launch.cache.json", true)||{}; - let a = launchCache.apps.find(a=>a.src===app.src); - if (a) { - a.wid = app.wid; - require("Storage").writeJSON("launch.cache.json", launchCache); - } - } + if (app.wid===undefined) exports.cacheWidgetsCheck([app]); // If we hadn't stored whether the app uses widgets before, check now // TODO: If there's a load screen boot app, we could call it? Or maybe Bangle.load should do that? if (app.wid || global.WIDGETS===undefined) Bangle.load(app.src) // if app uses widgets or we don't have any, we can fast load into it else if (Object.keys(WIDGETS).every(w=>!!WIDGETS[w].remove)) { // are widgets unloadable? !! needed before 2v29 fw @@ -72,6 +61,20 @@ exports.loadApp = function(app) { } else load(app.src); // otherwise default to slow load }; +exports.cacheWidgetsCheck = function(apps) { + let s = require("Storage"); + let launchCache = s.readJSON("launch.cache.json", true)||{}; + apps.forEach(app => { + let src = s.read(app.src) + app.wid = (src!==undefined)&&src.includes("Bangle.loadWidgets"); + // Now update the launch cache to save having to do this again + let a = launchCache.apps.find(a=>a.src===app.src); + if (a) a.wid = app.wid; + }); + s.writeJSON("launch.cache.json", launchCache); + return launchCache +} + /** delete the cache app list */ exports.clearCache = function() { require("Storage").erase("launch.cache.json"); // delete the cache app list