Update fuzzyw.app.js

pull/1659/head
sir-indy 2022-03-31 13:04:30 +01:00 committed by GitHub
parent cc0e5f14b1
commit 61c5c04c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 25 deletions

View File

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