From 66b0edf6c2d52d06356632e386ba3eff377133f4 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 24 Oct 2024 12:39:02 +0100 Subject: [PATCH] clock_info 0.13: Cache loaded ClockInfos so if we have clockInfoWidget and a clock, we don't load them twice (saves ~300ms) --- apps/clock_info/ChangeLog | 3 ++- apps/clock_info/lib.js | 8 ++++++++ apps/clock_info/metadata.json | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/clock_info/ChangeLog b/apps/clock_info/ChangeLog index 8276321ac..4fb438097 100644 --- a/apps/clock_info/ChangeLog +++ b/apps/clock_info/ChangeLog @@ -10,4 +10,5 @@ 0.09: Save clkinfo settings on kill and remove 0.10: Fix focus bug when changing focus between two clock infos 0.11: Prepend swipe listener if possible -0.12: Add drawFilledImage to allow drawing icons with a separately coloured middle \ No newline at end of file +0.12: Add drawFilledImage to allow drawing icons with a separately coloured middle +0.13: Cache loaded ClockInfos so if we have clockInfoWidget and a clock, we don't load them twice (saves ~300ms) \ No newline at end of file diff --git a/apps/clock_info/lib.js b/apps/clock_info/lib.js index a9ca7de31..7e0653c22 100644 --- a/apps/clock_info/lib.js +++ b/apps/clock_info/lib.js @@ -14,6 +14,8 @@ if (stepGoal == undefined) { exports.loadCount = 0; /// A list of all the instances returned by addInteractive exports.clockInfos = []; +/// A list of loaded clockInfos +exports.clockInfoMenus = undefined; /// Load the settings, with defaults exports.loadSettings = function() { @@ -29,6 +31,8 @@ exports.loadSettings = function() { /// Load a list of ClockInfos - this does not cache and reloads each time exports.load = function() { + if (exports.clockInfoMenus) + return exports.clockInfoMenus; var settings = exports.loadSettings(); delete settings.apps; // keep just the basic settings in memory // info used for drawing... @@ -146,6 +150,7 @@ exports.load = function() { }); // return it all! + exports.clockInfoMenus = menu; return menu; }; @@ -345,6 +350,9 @@ exports.addInteractive = function(menu, options) { menuHideItem(menu[options.menuA].items[options.menuB]); exports.loadCount--; delete exports.clockInfos[options.index]; + // If nothing loaded now, clear our list of loaded menus + if (exports.loadCount==0) + exports.clockInfoMenus = undefined; }; options.redraw = function() { drawItem(menu[options.menuA].items[options.menuB]); diff --git a/apps/clock_info/metadata.json b/apps/clock_info/metadata.json index 3d47c5062..46e230a60 100644 --- a/apps/clock_info/metadata.json +++ b/apps/clock_info/metadata.json @@ -1,7 +1,7 @@ { "id": "clock_info", "name": "Clock Info Module", "shortName": "Clock Info", - "version":"0.12", + "version":"0.13", "description": "A library used by clocks to provide extra information on the clock face (Altitude, BPM, etc)", "icon": "app.png", "type": "module",