diff --git a/modules/ClockFace.js b/modules/ClockFace.js index bf64d418a..1095b3613 100644 --- a/modules/ClockFace.js +++ b/modules/ClockFace.js @@ -41,10 +41,11 @@ function ClockFace(options) { this[k] = settings[k]; }); } - // these default to true - ["showDate", "loadWidgets"].forEach(k => { - if (this[k]===undefined) this[k] = true; - }); + // showDate defaults to true + if (this.showDate===undefined) this.showDate = true; + // if (old) setting was to not load widgets, default to hiding them + if (this.hideWidgets===undefined && this.loadWidgets===false) this.hideWidgets = 1; + let s = require("Storage").readJSON("setting.json",1)||{}; if ((global.__FILE__===undefined || global.__FILE__===s.clock) && s.clockHasWidgets!==this.loadWidgets) { @@ -92,7 +93,9 @@ ClockFace.prototype.start = function() { .CLOCK is set by Bangle.setUI('clock') but we want to load widgets so we can check appRect and *then* call setUI. see #1864 */ Bangle.CLOCK = 1; - if (this.loadWidgets) Bangle.loadWidgets(); + Bangle.loadWidgets(); + const widget_util = ["show", "hide", "swipeOn"][this.hideWidgets|0]; + require("widget_utils")[widget_util](); if (this.init) this.init.apply(this); const uiRemove = this._remove ? () => this.remove() : undefined; if (this._upDown) { @@ -133,6 +136,7 @@ ClockFace.prototype.resume = function() { }; ClockFace.prototype.remove = function() { this._removed = true; + require("widget_utils").show(); if (this._timeout) clearTimeout(this._timeout); Bangle.removeListener("lcdPower", this._onLcd); if (this._remove) this._remove.apply(this); diff --git a/modules/ClockFace.md b/modules/ClockFace.md index f123d38c0..36452cf85 100644 --- a/modules/ClockFace.md +++ b/modules/ClockFace.md @@ -140,7 +140,7 @@ For example: // now clock.showDate === false; clock.foo === 123; - clock.loadWidgets === true; // default when not in settings file + clock.hideWidgets === 0; // default when not in settings file clock.is12Hour === ??; // not in settings file: uses global setting clock.start(); @@ -152,13 +152,14 @@ The following properties are automatically set on the clock: * `is12Hour`: `true` if the "Time Format" setting is set to "12h", `false` for "24h". * `paused`: `true` while the clock is paused. (You don't need to check this inside your `draw()` code) * `showDate`: `true` (if not overridden through the settings file.) -* `loadWidgets`: `true` (if not overridden through the settings file.) - If set to `false` before calling `start()`, the clock won't call `Bangle.loadWidgets();` for you. - Best is to add a setting for this, but if you never want to load widgets, you could do this: +* `hideWidgets`: `0` (if not overridden through the settings file.) + If set to `1` before calling `start()`, the clock calls `require("widget_utils")hide();` for you. + (Bangle.js 2 only: `2` for swipe-down) + Best is to add a setting for this, but if you never want to show widgets, you could do this: ```js var ClockFace = require("ClockFace"); var clock = new ClockFace({draw: function(){/*...*/}}); - clock.loadWidgets = false; // prevent loading of widgets + clock.hideWidgets = 1; // hide widgets clock.start(); ``` @@ -200,7 +201,7 @@ let menu = { }; require("ClockFace_menu").addItems(menu, save, { showDate: settings.showDate, - loadWidgets: settings.loadWidgets, + hideWidgets: settings.hideWidgets, }); E.showMenu(menu); @@ -213,7 +214,7 @@ let menu = { /*LANG*/"< Back": back, }; require("ClockFace_menu").addSettingsFile(menu, ".settings.json", [ - "showDate", "loadWidgets", "powerSave", + "showDate", "hideWidgets", "powerSave", ]); E.showMenu(menu); diff --git a/modules/ClockFace_menu.js b/modules/ClockFace_menu.js index a1dd76fee..e78246f43 100644 --- a/modules/ClockFace_menu.js +++ b/modules/ClockFace_menu.js @@ -10,13 +10,12 @@ exports.addItems = function(menu, callback, items) { let value = items[key]; const label = { showDate:/*LANG*/"Show date", - loadWidgets:/*LANG*/"Load widgets", + hideWidgets:/*LANG*/"Widgets", powerSave:/*LANG*/"Power saving", }[key]; switch(key) { // boolean options which default to true case "showDate": - case "loadWidgets": if (value===undefined) value = true; // fall through case "powerSave": @@ -25,6 +24,17 @@ exports.addItems = function(menu, callback, items) { value: !!value, onchange: v => callback(key, v), }; + break; + + case "hideWidgets": + let options = [/*LANG*/"Show",/*LANG*/"Hide"]; + if (process.env.HWVERSION===2) options.push(/*LANG*/"Swipe"); + menu[label] = { + value: value|0, + min: 0, max: options.length-1, + format: v => options[v|0], + onchange: v => callback(key, v), + }; } }); }; @@ -39,6 +49,12 @@ exports.addItems = function(menu, callback, items) { exports.addSettingsFile = function(menu, settingsFile, items) { let s = require("Storage").readJSON(settingsFile, true) || {}; + // migrate "don't load widgets" to "hide widgets" + if (!("hideWidgets" in s) && ("loadWidgets" in s) && !s.loadWidgets) { + s.hideWidgets = 1; + } + delete s.loadWidgets; + function save(key, value) { s[key] = value; require("Storage").writeJSON(settingsFile, s);