diff --git a/apps/fuzzyw/fuzzyw.app.js b/apps/fuzzyw/fuzzyw.app.js index 988080ea1..ba1db294f 100644 --- a/apps/fuzzyw/fuzzyw.app.js +++ b/apps/fuzzyw/fuzzyw.app.js @@ -1,36 +1,38 @@ - // adapted from https://github.com/hallettj/Fuzzy-Text-International/ const fuzzy_strings = require("Storage").readJSON("fuzzy_strings.json"); const SETTINGS_FILE = "fuzzyw.settings.json"; -let settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'language': 'en_GB', 'alignment':'Centre'}; +let settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'language': 'System', 'alignment':'Centre'}; + +if (settings.language == 'System') { + settings.language = require('locale').name; +} let fuzzy_string = fuzzy_strings[settings.language]; -//let fuzzy_string = fuzzy_strings['en_GB']; const h = g.getHeight(); const w = g.getWidth(); function getTimeString(date) { -let segment = Math.round((date.getMinutes()*60 + date.getSeconds())/300); -let hour = date.getHours() + Math.floor(segment/12); -f_string = fuzzy_string.minutes[segment % 12]; -if (f_string.includes('$1')) { - f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 24]); -} else { - f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 24]); -} -return f_string; + let segment = Math.round((date.getMinutes()*60 + date.getSeconds())/300); + let hour = date.getHours() + Math.floor(segment/12); + f_string = fuzzy_string.minutes[segment % 12]; + if (f_string.includes('$1')) { + f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 24]); + } else { + f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 24]); + } + return f_string; } function draw() { -let time_string = getTimeString(new Date()).replace('*', ''); -// print(time_string); -g.setFont('Vector', (h-24*2)/fuzzy_string.text_scale); -g.setFontAlign(0, 0); -g.clearRect(0, 24, w, h-24); -g.setColor(g.theme.fg); -g.drawString(g.wrapString(time_string, w).join("\n"), w/2, h/2); + let time_string = getTimeString(new Date()).replace('*', ''); + // print(time_string); + g.setFont('Vector', (h-24*2)/fuzzy_string.text_scale); + g.setFontAlign(0, 0); + g.clearRect(0, 24, w, h-24); + g.setColor(g.theme.fg); + g.drawString(g.wrapString(time_string, w).join("\n"), w/2, h/2); } g.clear(); @@ -39,12 +41,12 @@ setInterval(draw, 10000); // refresh every 10s // Stop updates when LCD is off, restart when on Bangle.on('lcdPower',on=>{ -if (secondInterval) clearInterval(secondInterval); -secondInterval = undefined; -if (on) { - secondInterval = setInterval(draw, 10000); - draw(); // draw immediately -} + if (secondInterval) clearInterval(secondInterval); + secondInterval = undefined; + if (on) { + secondInterval = setInterval(draw, 10000); + draw(); // draw immediately + } }); Bangle.setUI('clock');