mirror of https://github.com/espruino/BangleApps
ClockFace: always loadWidgets, option to hide them using widget_utils
parent
059a2e7af7
commit
6980a0d9c9
|
@ -41,10 +41,11 @@ function ClockFace(options) {
|
||||||
this[k] = settings[k];
|
this[k] = settings[k];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// these default to true
|
// showDate defaults to true
|
||||||
["showDate", "loadWidgets"].forEach(k => {
|
if (this.showDate===undefined) this.showDate = true;
|
||||||
if (this[k]===undefined) this[k] = 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)||{};
|
let s = require("Storage").readJSON("setting.json",1)||{};
|
||||||
if ((global.__FILE__===undefined || global.__FILE__===s.clock)
|
if ((global.__FILE__===undefined || global.__FILE__===s.clock)
|
||||||
&& s.clockHasWidgets!==this.loadWidgets) {
|
&& 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*
|
.CLOCK is set by Bangle.setUI('clock') but we want to load widgets so we can check appRect and *then*
|
||||||
call setUI. see #1864 */
|
call setUI. see #1864 */
|
||||||
Bangle.CLOCK = 1;
|
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);
|
if (this.init) this.init.apply(this);
|
||||||
const uiRemove = this._remove ? () => this.remove() : undefined;
|
const uiRemove = this._remove ? () => this.remove() : undefined;
|
||||||
if (this._upDown) {
|
if (this._upDown) {
|
||||||
|
@ -133,6 +136,7 @@ ClockFace.prototype.resume = function() {
|
||||||
};
|
};
|
||||||
ClockFace.prototype.remove = function() {
|
ClockFace.prototype.remove = function() {
|
||||||
this._removed = true;
|
this._removed = true;
|
||||||
|
require("widget_utils").show();
|
||||||
if (this._timeout) clearTimeout(this._timeout);
|
if (this._timeout) clearTimeout(this._timeout);
|
||||||
Bangle.removeListener("lcdPower", this._onLcd);
|
Bangle.removeListener("lcdPower", this._onLcd);
|
||||||
if (this._remove) this._remove.apply(this);
|
if (this._remove) this._remove.apply(this);
|
||||||
|
|
|
@ -140,7 +140,7 @@ For example:
|
||||||
// now
|
// now
|
||||||
clock.showDate === false;
|
clock.showDate === false;
|
||||||
clock.foo === 123;
|
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.is12Hour === ??; // not in settings file: uses global setting
|
||||||
clock.start();
|
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".
|
* `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)
|
* `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.)
|
* `showDate`: `true` (if not overridden through the settings file.)
|
||||||
* `loadWidgets`: `true` (if not overridden through the settings file.)
|
* `hideWidgets`: `0` (if not overridden through the settings file.)
|
||||||
If set to `false` before calling `start()`, the clock won't call `Bangle.loadWidgets();` for you.
|
If set to `1` before calling `start()`, the clock calls `require("widget_utils")hide();` for you.
|
||||||
Best is to add a setting for this, but if you never want to load widgets, you could do this:
|
(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
|
```js
|
||||||
var ClockFace = require("ClockFace");
|
var ClockFace = require("ClockFace");
|
||||||
var clock = new ClockFace({draw: function(){/*...*/}});
|
var clock = new ClockFace({draw: function(){/*...*/}});
|
||||||
clock.loadWidgets = false; // prevent loading of widgets
|
clock.hideWidgets = 1; // hide widgets
|
||||||
clock.start();
|
clock.start();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -200,7 +201,7 @@ let menu = {
|
||||||
};
|
};
|
||||||
require("ClockFace_menu").addItems(menu, save, {
|
require("ClockFace_menu").addItems(menu, save, {
|
||||||
showDate: settings.showDate,
|
showDate: settings.showDate,
|
||||||
loadWidgets: settings.loadWidgets,
|
hideWidgets: settings.hideWidgets,
|
||||||
});
|
});
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
|
|
||||||
|
@ -213,7 +214,7 @@ let menu = {
|
||||||
/*LANG*/"< Back": back,
|
/*LANG*/"< Back": back,
|
||||||
};
|
};
|
||||||
require("ClockFace_menu").addSettingsFile(menu, "<appid>.settings.json", [
|
require("ClockFace_menu").addSettingsFile(menu, "<appid>.settings.json", [
|
||||||
"showDate", "loadWidgets", "powerSave",
|
"showDate", "hideWidgets", "powerSave",
|
||||||
]);
|
]);
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,12 @@ exports.addItems = function(menu, callback, items) {
|
||||||
let value = items[key];
|
let value = items[key];
|
||||||
const label = {
|
const label = {
|
||||||
showDate:/*LANG*/"Show date",
|
showDate:/*LANG*/"Show date",
|
||||||
loadWidgets:/*LANG*/"Load widgets",
|
hideWidgets:/*LANG*/"Widgets",
|
||||||
powerSave:/*LANG*/"Power saving",
|
powerSave:/*LANG*/"Power saving",
|
||||||
}[key];
|
}[key];
|
||||||
switch(key) {
|
switch(key) {
|
||||||
// boolean options which default to true
|
// boolean options which default to true
|
||||||
case "showDate":
|
case "showDate":
|
||||||
case "loadWidgets":
|
|
||||||
if (value===undefined) value = true;
|
if (value===undefined) value = true;
|
||||||
// fall through
|
// fall through
|
||||||
case "powerSave":
|
case "powerSave":
|
||||||
|
@ -25,6 +24,17 @@ exports.addItems = function(menu, callback, items) {
|
||||||
value: !!value,
|
value: !!value,
|
||||||
onchange: v => callback(key, v),
|
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) {
|
exports.addSettingsFile = function(menu, settingsFile, items) {
|
||||||
let s = require("Storage").readJSON(settingsFile, true) || {};
|
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) {
|
function save(key, value) {
|
||||||
s[key] = value;
|
s[key] = value;
|
||||||
require("Storage").writeJSON(settingsFile, s);
|
require("Storage").writeJSON(settingsFile, s);
|
||||||
|
|
Loading…
Reference in New Issue