Skip to content

Commit e34cd3d

Browse files
authored
Merge pull request espruino#3807 from voloved/moon_phase_hide
Added ability to hide moon phase widget
2 parents cc05172 + 942c2e1 commit e34cd3d

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

apps/widmp/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
0.07: Use default Bangle formatter for booleans
88
0.08: Better formula for the moon's phase
99
0.09: Fix variable declaration
10+
0.10: Added ability to hide widget

apps/widmp/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "widmp",
33
"name": "Moon Phase",
4-
"version": "0.09",
4+
"version": "0.10",
55
"description": "Display the current moon phase in blueish (in light mode) or white (in dark mode) for both hemispheres. In the southern hemisphere the 'My Location' app is needed.",
66
"icon": "widget.png",
77
"type": "widget",

apps/widmp/settings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var settings = Object.assign({
44
default_colour: true,
5+
hide: false,
56
red: 0,
67
green: 0,
78
blue: 0,
@@ -30,6 +31,13 @@
3031
writeSettings();
3132
}
3233
},
34+
"Hide Widget": {
35+
value: settings.hide,
36+
onchange: () => {
37+
settings.hide = !settings.hide;
38+
writeSettings();
39+
}
40+
},
3341
"Custom...": () => E.showMenu(custommenu)
3442
};
3543

apps/widmp/widget.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var lastCalculated = 0; // When we last calculated the phase
44
var phase = 0; // The last phase we calculated
55
var southernHemisphere = false; // when in southern hemisphere -- use the "My Location" App
6+
var settings;
67

78
// https://github.com/deirdreobyrne/LunarPhase
89
function moonPhase(sec) {
@@ -39,14 +40,18 @@
3940
g.drawLine(CenterX-leftFactor*y,CenterY+x, CenterX+rightFactor*y,CenterY+x);
4041
}
4142
}
42-
43-
function setMoonColour(g) {
44-
var settings = Object.assign({
43+
44+
function reloadSettings() {
45+
settings = Object.assign({
4546
default_colour: true,
47+
hide: false,
4648
red: 0,
4749
green: 0,
4850
blue: 0,
4951
}, require('Storage').readJSON("widmp.json", true) || {});
52+
}
53+
54+
function setMoonColour(g) {
5055
if (settings.default_colour) {
5156
if (g.theme.dark) {
5257
g.setColor(0xffff); // white
@@ -62,6 +67,7 @@
6267

6368

6469
function draw() {
70+
if (settings.hide) return;
6571
const CenterX = this.x + 12, CenterY = this.y + 12, Radius = 11;
6672
let leftFactor, rightFactor;
6773

@@ -90,9 +96,11 @@
9096
drawMoonPhase(CenterX,CenterY, Radius, leftFactor,rightFactor);
9197
}
9298

99+
reloadSettings();
100+
var wid = settings.hide ? 0 : 24;
93101
WIDGETS["widmp"] = {
94102
area: "tr",
95-
width: 24,
103+
width: wid,
96104
draw: draw
97105
};
98106

0 commit comments

Comments
 (0)