Skip to content

Commit 3d84679

Browse files
committed
smaller icon; properly scoped app; testing on hw
1 parent 88e0322 commit 3d84679

File tree

6 files changed

+34
-46
lines changed

6 files changed

+34
-46
lines changed

apps/jsonclock/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ inspired by [This FitBit face](https://github.com/Sharkgrammer/clockface.json)
1717
![](white.png)
1818
![](no_steps.png)
1919
![](no_location.png)
20+
![](dark-emulator.png)

apps/jsonclock/app-icon.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/jsonclock/app.js

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var SunCalc = require("suncalc"); // from modules folder
1+
{
2+
const SunCalc = require("suncalc"); // from modules folder
23
const storage = require('Storage');
34
const widget_utils = require('widget_utils');
45
const global_settings = storage.readJSON("setting.json", true) || {};
@@ -42,32 +43,32 @@ const maxLines = Math.floor(usableHeight / lineHeight);
4243
var numWidth = 0;
4344

4445
// requires the myLocation app
45-
function loadLocation() {
46+
let loadLocation = function() {
4647
location = require("Storage").readJSON(LOCATION_FILE, 1) || {};
4748
location.lat = location.lat || 0;
4849
location.lon = location.lon || 0;
4950
location.location = location.location || null;
50-
}
51+
};
5152

52-
function getHr(h) {
53+
let getHr = function(h) {
5354
var amPm = "";
5455
if (settings.hr_12) {
5556
amPm = h < 12 ? "AM" : "PM";
5657
h = h % 12;
5758
if (h == 0) h = 12;
5859
}
5960
return [h, amPm];
60-
}
61+
};
6162

62-
function extractTime(d) {
63+
let extractTime = function(d) {
6364
const out = getHr(d.getHours());
6465
const h = out[0];
6566
const amPm = out[1];
6667
const m = d.getMinutes();
6768
return `${h}:${("0"+m).substr(-2)}${amPm}`;
68-
}
69+
};
6970

70-
function extractDate(d) {
71+
let extractDate = function(d) {
7172
const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
7273
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
7374
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
@@ -78,9 +79,9 @@ function extractDate(d) {
7879
const day = d.getDate();
7980

8081
return `${weekday} ${month} ${day}`;
81-
}
82+
};
8283

83-
function getSteps() {
84+
let getSteps = function() {
8485
try {
8586
return Bangle.getHealthStatus("day").steps;
8687
} catch (e) {
@@ -89,9 +90,9 @@ function getSteps() {
8990
else
9091
return null;
9192
}
92-
}
93+
};
9394

94-
function getVal(now, loc) {
95+
let getVal = function(now, loc) {
9596
const vals = {};
9697
const currentDateStr = extractDate(now);
9798
if (loc.location) {
@@ -107,10 +108,9 @@ function getVal(now, loc) {
107108
vals.batt_pct = E.getBattery();
108109
vals.steps = getSteps();
109110
return vals;
110-
}
111-
111+
};
112112

113-
function loadJson() {
113+
let loadJson = function() {
114114
const now = new Date();
115115
vals = getVal(now, location);
116116
//vals.steps = null; // For testing; uncomment to see the steps not appear
@@ -142,9 +142,9 @@ function loadJson() {
142142

143143
jsonText = JSON.stringify(raw, null, 2); // just stringify the object
144144
lines = jsonText.split("\n");
145-
}
145+
};
146146

147-
function draw() {
147+
let draw = function() {
148148
g.clear();
149149
g.setFontAlign(-1, -1);
150150
g.setFont("Vector", 10);
@@ -169,9 +169,9 @@ function draw() {
169169
}
170170

171171
redraw();
172-
}
172+
};
173173

174-
function redraw() {
174+
let redraw = function() {
175175
for (let i = 0; i < maxLines; i++) {
176176
const lineIndex = i;
177177
const line = lines[lineIndex];
@@ -217,19 +217,18 @@ function redraw() {
217217
g.drawString(line, numWidth, y);
218218
}
219219
}
220-
Bangle.drawWidgets();
221-
}
220+
};
222221

223-
function clearVals() {
222+
let clearVals = function() {
224223
g.setFont("Vector", fontSize);
225224
g.setFontAlign(-1, -1);
226225
valuePositions.forEach(pos => {
227226
g.setColor(clrs.bg);
228227
g.fillRect(pos.x, pos.y, w, pos.y + lineHeight);
229228
});
230-
}
229+
};
231230

232-
function redrawValues() {
231+
let redrawValues = function() {
233232
loadJson();
234233
clearVals();
235234
redraw();
@@ -238,12 +237,12 @@ function redrawValues() {
238237
drawTimeout = undefined;
239238
redrawValues();
240239
}, 60000 - (Date.now() % 60000));
241-
}
240+
};
242241

243242
Bangle.on('touch', (zone, e) => {
244243
if (e.x >= (buttonY - buttonHeight) && e.x <= (buttonX + buttonHeight) &&
245244
(e.y >= (buttonY - buttonHeight) && e.y <= (buttonY + buttonHeight))) {
246-
load(); // Exit app
245+
Bangle.showLauncher(); // Exit app
247246
}
248247
});
249248

@@ -253,16 +252,9 @@ Bangle.on('backlight', function(on) {
253252
}
254253
});
255254

256-
Bangle.setUI({
257-
mode: "clock",
258-
remove: function() {
259-
if (drawTimeout) clearTimeout(drawTimeout);
260-
drawTimeout = undefined;
261-
}
262-
});
263-
255+
Bangle.setUI("clock");
264256
loadLocation();
265257
Bangle.loadWidgets();
266258
widget_utils.hide();
267259
draw();
268-
setTimeout(Bangle.drawWidgets, 0);
260+
}

apps/jsonclock/app.png

-1.23 KB
Loading

apps/jsonclock/dark-emulator.png

3.68 KB
Loading

apps/jsonclock/metadata.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
{ "id": "jsonclock",
2-
"name": "jsonclock",
2+
"name": "JsonClock",
33
"version": "0.01",
4-
"dependencies": {"mylocation":"app"},
54
"description": "JSON view of the time, date, steps, battery, and sunrise and sunset times",
65
"icon": "app.png",
6+
"screenshots": [{"url":"app.png"}],
77
"type": "clock",
88
"tags": "clock",
9-
"supports" : ["BANGLEJS2"],
10-
"screenshots": [{"url":"app.png"}],
11-
"readme": "README.md",
9+
"supports": ["BANGLEJS","BANGLEJS2"],
1210
"storage": [
1311
{"name":"jsonclock.app.js","url":"app.js"},
14-
{"name":"jsonclock.img","url":"app-icon.js","evaluate":true},
15-
{"name":"jsonclock.settings.js","url":"settings.js"}
16-
],
17-
"data": [{"name":"jsonclock.json"}],
18-
"sortorder": -9
12+
{"name":"jsonclock.img","url":"app-icon.js","evaluate":true}
13+
]
1914
}

0 commit comments

Comments
 (0)