From 4c51cd29d82050ba85cd5d6ecdf4587cedb9d5e4 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 5 May 2023 13:52:00 +0100 Subject: [PATCH] remove undefined filter warning --- loader.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/loader.js b/loader.js index 257c29825..9b1b3ee84 100644 --- a/loader.js +++ b/loader.js @@ -107,22 +107,24 @@ function filterAppsForDevice(deviceId) { // set the device dropdown document.querySelector(".devicetype-nav span").innerText = device ? device.name : "All apps"; - if (!device) { - if (deviceId!==undefined) - showToast(`Device ID ${deviceId} not recognised. Some apps may not work`, "warning"); - appJSON = originalAppJSON; - } else { - // Now filter apps - appJSON = originalAppJSON.filter(app => { - var supported = ["BANGLEJS"]; - if (!app.supports) { - console.log(`App ${app.id} doesn't include a 'supports' field - ignoring`); + if (originalAppJSON) { // JSON might not have loaded yet + if (!device) { + if (deviceId!==undefined) + showToast(`Device ID ${deviceId} not recognised. Some apps may not work`, "warning"); + appJSON = originalAppJSON; + } else { + // Now filter apps + appJSON = originalAppJSON.filter(app => { + var supported = ["BANGLEJS"]; + if (!app.supports) { + console.log(`App ${app.id} doesn't include a 'supports' field - ignoring`); + return false; + } + if (app.supports.includes(deviceId)) return true; + //console.log(`Dropping ${app.id} because ${deviceId} is not in supported list ${app.supports.join(",")}`); return false; - } - if (app.supports.includes(deviceId)) return true; - //console.log(`Dropping ${app.id} because ${deviceId} is not in supported list ${app.supports.join(",")}`); - return false; - }); + }); + } } refreshLibrary(); }