1
0
Fork 0

clock_info 0.13: Cache loaded ClockInfos so if we have clockInfoWidget and a clock, we don't load them twice (saves ~300ms)

master
Gordon Williams 2024-10-24 12:39:02 +01:00
parent c893bc849f
commit 66b0edf6c2
3 changed files with 11 additions and 2 deletions

View File

@ -10,4 +10,5 @@
0.09: Save clkinfo settings on kill and remove 0.09: Save clkinfo settings on kill and remove
0.10: Fix focus bug when changing focus between two clock infos 0.10: Fix focus bug when changing focus between two clock infos
0.11: Prepend swipe listener if possible 0.11: Prepend swipe listener if possible
0.12: Add drawFilledImage to allow drawing icons with a separately coloured middle 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)

View File

@ -14,6 +14,8 @@ if (stepGoal == undefined) {
exports.loadCount = 0; exports.loadCount = 0;
/// A list of all the instances returned by addInteractive /// A list of all the instances returned by addInteractive
exports.clockInfos = []; exports.clockInfos = [];
/// A list of loaded clockInfos
exports.clockInfoMenus = undefined;
/// Load the settings, with defaults /// Load the settings, with defaults
exports.loadSettings = function() { exports.loadSettings = function() {
@ -29,6 +31,8 @@ exports.loadSettings = function() {
/// Load a list of ClockInfos - this does not cache and reloads each time /// Load a list of ClockInfos - this does not cache and reloads each time
exports.load = function() { exports.load = function() {
if (exports.clockInfoMenus)
return exports.clockInfoMenus;
var settings = exports.loadSettings(); var settings = exports.loadSettings();
delete settings.apps; // keep just the basic settings in memory delete settings.apps; // keep just the basic settings in memory
// info used for drawing... // info used for drawing...
@ -146,6 +150,7 @@ exports.load = function() {
}); });
// return it all! // return it all!
exports.clockInfoMenus = menu;
return menu; return menu;
}; };
@ -345,6 +350,9 @@ exports.addInteractive = function(menu, options) {
menuHideItem(menu[options.menuA].items[options.menuB]); menuHideItem(menu[options.menuA].items[options.menuB]);
exports.loadCount--; exports.loadCount--;
delete exports.clockInfos[options.index]; 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() { options.redraw = function() {
drawItem(menu[options.menuA].items[options.menuB]); drawItem(menu[options.menuA].items[options.menuB]);

View File

@ -1,7 +1,7 @@
{ "id": "clock_info", { "id": "clock_info",
"name": "Clock Info Module", "name": "Clock Info Module",
"shortName": "Clock Info", "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)", "description": "A library used by clocks to provide extra information on the clock face (Altitude, BPM, etc)",
"icon": "app.png", "icon": "app.png",
"type": "module", "type": "module",