From 50c2d8e206694e0f26024a033e10eaaaf37314bb Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 17 Apr 2024 22:21:06 +0100 Subject: [PATCH] [thunder] Use the locale module to display distance Signed-off-by: James Taylor --- apps/thunder/ChangeLog | 1 + apps/thunder/app.js | 12 ++++++++++-- apps/thunder/metadata.json | 3 ++- apps/thunder/settings.js | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/thunder/ChangeLog b/apps/thunder/ChangeLog index 5560f00bc..4e9c694a5 100644 --- a/apps/thunder/ChangeLog +++ b/apps/thunder/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Use locale module to display distance diff --git a/apps/thunder/app.js b/apps/thunder/app.js index d180bb720..ca213c64d 100644 --- a/apps/thunder/app.js +++ b/apps/thunder/app.js @@ -7,6 +7,8 @@ Bangle.setLCDTimeout(undefined); let renderIntervalId; let startTime; +const locale = require("locale"); + const DEFAULTS = { units: 0, }; @@ -29,6 +31,9 @@ var layout = new Layout( { back: load, }); +// TODO The code in this function appears in various apps so it might be +// nice to add something to the time_utils module. (There is already a +// formatDuration function but that doesn't quite work the same way.) const getTime = function(milliseconds) { let hrs = Math.floor(milliseconds/3600000); let mins = Math.floor(milliseconds/60000)%60; @@ -52,12 +57,15 @@ const getDistance = function(milliseconds) { let secs = milliseconds/1000; let distance; - if (settings.units === 0) { + if (settings.units === 1) { let kms = Math.round((secs / 2.91) * 10) / 10; distance = kms.toFixed(1) + "km"; - } else { + } else if (settings.units === 2) { let miles = Math.round((secs / 4.69) * 10) / 10; distance = miles.toFixed(1) + "mi"; + } else { + let meters = (secs / 2.91) * 1000; + distance = locale.distance(meters); } return distance; diff --git a/apps/thunder/metadata.json b/apps/thunder/metadata.json index 46696095e..e8812a3c4 100644 --- a/apps/thunder/metadata.json +++ b/apps/thunder/metadata.json @@ -1,12 +1,13 @@ { "id": "thunder", "name": "Come on Thunder", "shortName":"Thunder", - "version":"0.01", + "version":"0.02", "description": "Simple timer to calculate how far away lightning is", "icon": "app.png", "tags": "tool,weather", "supports" : ["BANGLEJS2"], "readme": "README.md", + "screenshots": [{ "url": "screenshot.png" }], "allow_emulator": true, "storage": [ {"name":"thunder.app.js","url":"app.js"}, diff --git a/apps/thunder/settings.js b/apps/thunder/settings.js index bbbf43c54..1a2959227 100644 --- a/apps/thunder/settings.js +++ b/apps/thunder/settings.js @@ -15,7 +15,7 @@ }; const showMenu = function() { - const unitOptions = ['kms','miles']; + const unitOptions = [/*LANG*/'Auto','kms','miles']; const menu = { '': {'title': 'Thunder'},