From 779b16b67177cf8096f304113773acae8d6d38d0 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Tue, 1 Nov 2022 14:21:27 +0000 Subject: [PATCH] Fix for issue where launcher would fast-load back to clock even if the clock didn't have widgets --- apps/boot/ChangeLog | 1 + apps/boot/bootloader.js | 8 +++++++- apps/launch/app.js | 4 ++-- apps/setting/ChangeLog | 2 +- apps/setting/metadata.json | 2 +- apps/setting/settings.js | 18 ++++++++---------- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 05b7050c4..3bd1fc9fd 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -57,3 +57,4 @@ Remove support for 2v11 and earlier firmware 0.51: Remove patches for 2v10 firmware (BEEPSET and setUI) Add patch to ensure that compass heading is corrected + Ensure clock is only fast-loaded if it doesn't contain widgets diff --git a/apps/boot/bootloader.js b/apps/boot/bootloader.js index 1e0d22645..6e6466f48 100644 --- a/apps/boot/bootloader.js +++ b/apps/boot/bootloader.js @@ -1,5 +1,10 @@ // This runs after a 'fresh' boot var s = require("Storage").readJSON("setting.json",1)||{}; +/* If were being called from JS code in order to load the clock quickly (eg from a launcher) +and the clock in question doesn't have widgets, force a normal 'load' as this will then +reset everything and remove the widgets. */ +if (global.__FILE__ && !s.clockHasWidgets) {load();throw "Clock has no widgets, can't fast load";} +// Otherwise continue to try and load the clock var _clkApp = require("Storage").read(s.clock); if (!_clkApp) { _clkApp = require("Storage").list(/\.info$/) @@ -13,7 +18,8 @@ if (!_clkApp) { .sort((a, b) => a.sortorder - b.sortorder)[0]; if (_clkApp){ s.clock = _clkApp.src; - _clkApp = require("Storage").read(_clkApp.src); + _clkApp = require("Storage").read(_clkApp.src); + s.clockHasWidgets = _clkApp.includes("Bangle.loadWidgets"); require("Storage").writeJSON("setting.json", s); } } diff --git a/apps/launch/app.js b/apps/launch/app.js index 05f5bef43..3b33e530a 100644 --- a/apps/launch/app.js +++ b/apps/launch/app.js @@ -66,7 +66,7 @@ E.showScroller({ }); g.flip(); // force a render before widgets have finished drawing -function returnToClock() { +let returnToClock = function() { // unload everything manually // ... or we could just call `load();` but it will be slower Bangle.setUI(); // remove scroller's handling @@ -85,7 +85,7 @@ if (process.env.HWVERSION==2) { // 10s of inactivity goes back to clock Bangle.setLocked(false); // unlock initially let lockTimeout; -function lockHandler(locked) { +let lockHandler = function(locked) { if (lockTimeout) clearTimeout(lockTimeout); lockTimeout = undefined; if (locked) diff --git a/apps/setting/ChangeLog b/apps/setting/ChangeLog index 25adad359..cd97e1dda 100644 --- a/apps/setting/ChangeLog +++ b/apps/setting/ChangeLog @@ -57,4 +57,4 @@ 0.50: Add Bangle.js 2 touchscreen calibration - for 2v16 or 2v15 cutting edge builds 0.51: Add setting for configuring a launcher 0.52: Add option for left-handed users - +0.53: Ensure that when clock is set, clockHasWidgets is set correctly too diff --git a/apps/setting/metadata.json b/apps/setting/metadata.json index 3a3094a4e..47d0a309f 100644 --- a/apps/setting/metadata.json +++ b/apps/setting/metadata.json @@ -1,7 +1,7 @@ { "id": "setting", "name": "Settings", - "version": "0.52", + "version": "0.53", "description": "A menu for setting up Bangle.js", "icon": "settings.png", "tags": "tool,system", diff --git a/apps/setting/settings.js b/apps/setting/settings.js index 5d3bd3705..d7bb060ea 100644 --- a/apps/setting/settings.js +++ b/apps/setting/settings.js @@ -39,6 +39,7 @@ function resetSettings() { timezone: 0, // Set the timezone for the device HID: false, // BLE HID mode, off by default clock: null, // a string for the default clock's name + // clockHasWidgets: false, // Does the clock in 'clock' contain the string 'Bangle.loadWidgets' "12hour" : false, // 12 or 24 hour clock? firstDayOfWeek: 0, // 0 -> Sunday (default), 1 -> Monday brightness: 1, // LCD brightness from 0 to 1 @@ -674,11 +675,10 @@ function showClockMenu() { label = "* " + label; } clockMenu[label] = () => { - if (settings.clock !== app.src) { - settings.clock = app.src; - updateSettings(); - showMainMenu(); - } + settings.clock = app.src; + settings.clockHasWidgets = require("Storage").read(app.src).includes("Bangle.loadWidgets"); + updateSettings(); + showMainMenu(); }; }); if (clockApps.length === 0) { @@ -703,11 +703,9 @@ function showLauncherMenu() { label = "* " + label; } launcherMenu[label] = () => { - if (settings.launcher !== app.src) { - settings.launcher = app.src; - updateSettings(); - showMainMenu(); - } + settings.launcher = app.src; + updateSettings(); + showMainMenu(); }; }); if (launcherApps.length === 0) {