From a56a9792f15499ed3ee6f74a1fe6c70a5f22ab3d Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 15 Apr 2020 13:58:05 +0100 Subject: [PATCH] Rewrite 'getInstalledApps' to minimize RAM usage --- CHANGELOG.md | 1 + js/comms.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9480f2ace..95e973e0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ Changed for individual apps are listed in `apps/appname/ChangeLog` * Fix issue removing an app that was just installed (fix #253) * Add `Favourite` functionality * Version number now clickable even when you're at the latest version (fix #291) +* Rewrite 'getInstalledApps' to minimize RAM usage diff --git a/js/comms.js b/js/comms.js index 604ef19ed..1f840ada7 100644 --- a/js/comms.js +++ b/js/comms.js @@ -75,12 +75,21 @@ getInstalledApps : () => { Progress.hide({sticky:true}); return reject(""); } - Puck.eval('require("Storage").list(/\.info$/).map(f=>{var j=require("Storage").readJSON(f,1)||{};j.id=f.slice(0,-5);return j})', (appList,err) => { + Puck.write('\x10Bluetooth.print("[");require("Storage").list(/\.info$/).forEach(f=>{var j=require("Storage").readJSON(f,1)||{};j.id=f.slice(0,-5);Bluetooth.print(JSON.stringify(j)+",")});Bluetooth.println("0]")\n', (appList,err) => { Progress.hide({sticky:true}); + try { + appList = JSON.parse(appList); + // remove last element since we added a final '0' + // to make things easy on the Bangle.js side + appList = appList.slice(0,-1); + } catch (e) { + appList = null; + err = e.toString(); + } if (appList===null) return reject(err || ""); console.log("getInstalledApps", appList); resolve(appList); - }); + }, true /* callback on newline */); }); }); },