Fix indentation

master
Tanner Collin 1 year ago
parent 9e45acb78e
commit 7fadeabf33
  1. 732
      messagegui/app.js

@ -1,14 +1,14 @@
/* MESSAGES is a list of: /* MESSAGES is a list of:
{id:int, {id:int,
src, src,
title, title,
subject, subject,
body, body,
sender, sender,
tel:string, tel:string,
new:true // not read yet new:true // not read yet
} }
*/ */
/* For example for maps: /* For example for maps:
@ -29,16 +29,16 @@ var active; // active screen
var openMusic = false; // go back to music screen after we handle something else? var openMusic = false; // go back to music screen after we handle something else?
// hack for 2v10 firmware's lack of ':size' font handling // hack for 2v10 firmware's lack of ':size' font handling
try { try {
g.setFont("6x8:2"); g.setFont("6x8:2");
} catch (e) { } catch (e) {
g._setFont = g.setFont; g._setFont = g.setFont;
g.setFont = function(f,s) { g.setFont = function(f,s) {
if (f.includes(":")) { if (f.includes(":")) {
f = f.split(":"); f = f.split(":");
return g._setFont(f[0],f[1]); return g._setFont(f[0],f[1]);
} }
return g._setFont(f,s); return g._setFont(f,s);
}; };
} }
/** this is a timeout if the app has started and is showing a single message /** this is a timeout if the app has started and is showing a single message
@ -49,303 +49,303 @@ var unreadTimeout;
/// List of all our messages /// List of all our messages
var MESSAGES = require("messages").getMessages(); var MESSAGES = require("messages").getMessages();
if (Bangle.MESSAGES) { if (Bangle.MESSAGES) {
// fast loading messages // fast loading messages
Bangle.MESSAGES.forEach(m => require("messages").apply(m, MESSAGES)); Bangle.MESSAGES.forEach(m => require("messages").apply(m, MESSAGES));
delete Bangle.MESSAGES; delete Bangle.MESSAGES;
} }
var onMessagesModified = function(type,msg) { var onMessagesModified = function(type,msg) {
if (msg.handled) return; if (msg.handled) return;
msg.handled = true; msg.handled = true;
require("messages").apply(msg, MESSAGES); require("messages").apply(msg, MESSAGES);
// TODO: if new, show this new one // TODO: if new, show this new one
if (msg && msg.id!=="music" && msg.new && active!="map" && if (msg && msg.id!=="music" && msg.new && active!="map" &&
!((require('Storage').readJSON('setting.json', 1) || {}).quiet)) { !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) {
require("messages").buzz(msg.src); require("messages").buzz(msg.src);
} }
if (msg && msg.id=="music") { if (msg && msg.id=="music") {
if (msg.state && msg.state!="play") openMusic = false; // no longer playing music to go back to if (msg.state && msg.state!="play") openMusic = false; // no longer playing music to go back to
if (active!="music") return; // don't open music over other screens if (active!="music") return; // don't open music over other screens
} }
showMessage(msg&&msg.id); showMessage(msg&&msg.id);
}; };
Bangle.on("message", onMessagesModified); Bangle.on("message", onMessagesModified);
function saveMessages() { function saveMessages() {
require("messages").write(MESSAGES); require("messages").write(MESSAGES);
} }
E.on("kill", saveMessages); E.on("kill", saveMessages);
function showMapMessage(msg) { function showMapMessage(msg) {
active = "map"; active = "map";
var m, distance, street, target, eta; var m, distance, street, target, eta;
m=msg.title.match(/(.*) - (.*)/); m=msg.title.match(/(.*) - (.*)/);
if (m) { if (m) {
distance = m[1]; distance = m[1];
street = m[2]; street = m[2];
} else street=msg.title; } else street=msg.title;
m=msg.body.match(/(.*) - (.*)/); m=msg.body.match(/(.*) - (.*)/);
if (m) { if (m) {
target = m[1]; target = m[1];
eta = m[2]; eta = m[2];
} else target=msg.body; } else target=msg.body;
layout = new Layout({ type:"v", c: [ layout = new Layout({ type:"v", c: [
{type:"txt", font:fontMedium, label:target, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }, {type:"txt", font:fontMedium, label:target, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 },
{type:"h", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, c: [ {type:"h", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, c: [
{type:"txt", font:"6x8", label:"Towards" }, {type:"txt", font:"6x8", label:"Towards" },
{type:"txt", font:fontLarge, label:street } {type:"txt", font:fontLarge, label:street }
]}, ]},
{type:"h",fillx:1, filly:1, c: [ {type:"h",fillx:1, filly:1, c: [
msg.img?{type:"img",src:atob(msg.img), scale:2}:{}, msg.img?{type:"img",src:atob(msg.img), scale:2}:{},
{type:"v", fillx:1, c: [ {type:"v", fillx:1, c: [
{type:"txt", font:fontLarge, label:distance||"" } {type:"txt", font:fontLarge, label:distance||"" }
]}, ]},
]}, ]},
{type:"txt", font:"6x8:2", label:eta } {type:"txt", font:"6x8:2", label:eta }
]}); ]});
g.reset().clearRect(Bangle.appRect); g.reset().clearRect(Bangle.appRect);
layout.render(); layout.render();
function back() { // mark as not new and return to menu function back() { // mark as not new and return to menu
msg.new = false; msg.new = false;
layout = undefined; layout = undefined;
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
} }
Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back
} }
let updateLabelsInterval; let updateLabelsInterval;
function showMusicMessage(msg) { function showMusicMessage(msg) {
active = "music"; active = "music";
// defaults, so e.g. msg.xyz.length doesn't error. `msg` should contain up to date info // defaults, so e.g. msg.xyz.length doesn't error. `msg` should contain up to date info
msg = Object.assign({artist: "", album: "", track: "Music"}, msg); msg = Object.assign({artist: "", album: "", track: "Music"}, msg);
openMusic = msg.state=="play"; openMusic = msg.state=="play";
var trackScrollOffset = 0; var trackScrollOffset = 0;
var artistScrollOffset = 0; var artistScrollOffset = 0;
var albumScrollOffset = 0; var albumScrollOffset = 0;
var trackName = ''; var trackName = '';
var artistName = ''; var artistName = '';
var albumName = ''; var albumName = '';
function fmtTime(s) { function fmtTime(s) {
var m = Math.floor(s/60); var m = Math.floor(s/60);
s = (parseInt(s%60)).toString().padStart(2,0); s = (parseInt(s%60)).toString().padStart(2,0);
return m+":"+s; return m+":"+s;
} }
function reduceStringAndPad(text, offset, maxLen) { function reduceStringAndPad(text, offset, maxLen) {
var sliceLength = offset + maxLen > text.length ? text.length - offset : maxLen; var sliceLength = offset + maxLen > text.length ? text.length - offset : maxLen;
return text.substr(offset, sliceLength).padEnd(maxLen, " "); return text.substr(offset, sliceLength).padEnd(maxLen, " ");
} }
function back() { function back() {
clearInterval(updateLabelsInterval); clearInterval(updateLabelsInterval);
updateLabelsInterval = undefined; updateLabelsInterval = undefined;
openMusic = false; openMusic = false;
var wasNew = msg.new; var wasNew = msg.new;
msg.new = false; msg.new = false;
layout = undefined; layout = undefined;
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0}); if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
} }
function updateLabels() { function updateLabels() {
trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13); trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13);
artistName = reduceStringAndPad(msg.artist, artistScrollOffset, 21); artistName = reduceStringAndPad(msg.artist, artistScrollOffset, 21);
albumName = reduceStringAndPad(msg.album, albumScrollOffset, 21); albumName = reduceStringAndPad(msg.album, albumScrollOffset, 21);
trackScrollOffset++; trackScrollOffset++;
artistScrollOffset++; artistScrollOffset++;
albumScrollOffset++; albumScrollOffset++;
if ((trackScrollOffset + 13) > msg.track.length) trackScrollOffset = 0; if ((trackScrollOffset + 13) > msg.track.length) trackScrollOffset = 0;
if ((artistScrollOffset + 21) > msg.artist.length) artistScrollOffset = 0; if ((artistScrollOffset + 21) > msg.artist.length) artistScrollOffset = 0;
if ((albumScrollOffset + 21) > msg.album.length) albumScrollOffset = 0; if ((albumScrollOffset + 21) > msg.album.length) albumScrollOffset = 0;
} }
updateLabels(); updateLabels();
layout = new Layout({ type:"v", c: [ layout = new Layout({ type:"v", c: [
{type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [ {type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [
{ type:"v", fillx:1, c: [ { type:"v", fillx:1, c: [
{ type:"txt", font:fontMedium, bgCol:g.theme.bg2, label:artistName, pad:2, id:"artist" }, { type:"txt", font:fontMedium, bgCol:g.theme.bg2, label:artistName, pad:2, id:"artist" },
{ type:"txt", font:fontMedium, bgCol:g.theme.bg2, label:albumName, pad:2, id:"album" } { type:"txt", font:fontMedium, bgCol:g.theme.bg2, label:albumName, pad:2, id:"album" }
]} ]}
]}, ]},
{type:"txt", font:fontLarge, bgCol:g.theme.bg, label:trackName, fillx:1, filly:1, pad:2, id:"track" }, {type:"txt", font:fontLarge, bgCol:g.theme.bg, label:trackName, fillx:1, filly:1, pad:2, id:"track" },
Bangle.musicControl?{type:"h",fillx:1, c: [ Bangle.musicControl?{type:"h",fillx:1, c: [
{type:"btn", pad:8, label:"\0"+atob("FhgBwAADwAAPwAA/wAD/gAP/gA//gD//gP//g///j///P//////////P//4//+D//gP/4A/+AD/gAP8AA/AADwAAMAAA"), cb:()=>Bangle.musicControl("play")}, // play {type:"btn", pad:8, label:"\0"+atob("FhgBwAADwAAPwAA/wAD/gAP/gA//gD//gP//g///j///P//////////P//4//+D//gP/4A/+AD/gAP8AA/AADwAAMAAA"), cb:()=>Bangle.musicControl("play")}, // play
{type:"btn", pad:8, label:"\0"+atob("EhaBAHgHvwP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP3gHg"), cb:()=>Bangle.musicControl("pause")}, // pause {type:"btn", pad:8, label:"\0"+atob("EhaBAHgHvwP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP/wP3gHg"), cb:()=>Bangle.musicControl("pause")}, // pause
{type:"btn", pad:8, label:"\0"+atob("EhKBAMAB+AB/gB/wB/8B/+B//B//x//5//5//x//B/+B/8B/wB/gB+AB8ABw"), cb:()=>Bangle.musicControl("next")}, // next {type:"btn", pad:8, label:"\0"+atob("EhKBAMAB+AB/gB/wB/8B/+B//B//x//5//5//x//B/+B/8B/wB/gB+AB8ABw"), cb:()=>Bangle.musicControl("next")}, // next
]}:{}, ]}:{},
{type:"txt", font:"6x8:2", label:msg.dur?fmtTime(msg.dur):"--:--" } {type:"txt", font:"6x8:2", label:msg.dur?fmtTime(msg.dur):"--:--" }
]}, { back : back }); ]}, { back : back });
g.reset().clearRect(Bangle.appRect); g.reset().clearRect(Bangle.appRect);
layout.render(); layout.render();
updateLabelsInterval = setInterval(function() { updateLabelsInterval = setInterval(function() {
updateLabels(); updateLabels();
layout.artist.label = artistName; layout.artist.label = artistName;
layout.album.label = albumName; layout.album.label = albumName;
layout.track.label = trackName; layout.track.label = trackName;
layout.render(); layout.render();
}, 400); }, 400);
} }
function showMessageScroller(msg) { function showMessageScroller(msg) {
active = "scroller"; active = "scroller";
var bodyFont = fontBig; var bodyFont = fontBig;
g.setFont(bodyFont); g.setFont(bodyFont);
var lines = []; var lines = [];
if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10) if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10)
var titleCnt = lines.length; var titleCnt = lines.length;
if (titleCnt) lines.push(""); // add blank line after title if (titleCnt) lines.push(""); // add blank line after title
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10),["",/*LANG*/"< Back"]); lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10),["",/*LANG*/"< Back"]);
E.showScroller({ E.showScroller({
h : g.getFontHeight(), // height of each menu item in pixels h : g.getFontHeight(), // height of each menu item in pixels
c : lines.length, // number of menu items c : lines.length, // number of menu items
// a function to draw a menu item // a function to draw a menu item
draw : function(idx, r) { draw : function(idx, r) {
// FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12 // FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12
g.setBgColor(idx<titleCnt ? g.theme.bg2 : g.theme.bg). g.setBgColor(idx<titleCnt ? g.theme.bg2 : g.theme.bg).
setColor(idx<titleCnt ? g.theme.fg2 : g.theme.fg). setColor(idx<titleCnt ? g.theme.fg2 : g.theme.fg).
clearRect(r.x,r.y,r.x+r.w, r.y+r.h); clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
g.setFont(bodyFont).drawString(lines[idx], r.x, r.y); g.setFont(bodyFont).drawString(lines[idx], r.x, r.y);
}, select : function(idx) { }, select : function(idx) {
if (idx>=lines.length-2) if (idx>=lines.length-2)
showMessage(msg.id); showMessage(msg.id);
}, },
back : () => showMessage(msg.id) back : () => showMessage(msg.id)
}); });
} }
function showMessageSettings(msg) { function showMessageSettings(msg) {
active = "settings"; active = "settings";
E.showMenu({"":{"title":/*LANG*/"Message"}, E.showMenu({"":{"title":/*LANG*/"Message"},
"< Back" : () => showMessage(msg.id), "< Back" : () => showMessage(msg.id),
/*LANG*/"View Message" : () => { /*LANG*/"View Message" : () => {
showMessageScroller(msg); showMessageScroller(msg);
}, },
/*LANG*/"Delete" : () => { /*LANG*/"Delete" : () => {
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id); MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}, },
/*LANG*/"Mark Unread" : () => { /*LANG*/"Mark Unread" : () => {
msg.new = true; msg.new = true;
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}, },
/*LANG*/"Mark all read" : () => { /*LANG*/"Mark all read" : () => {
MESSAGES.forEach(msg => msg.new = false); MESSAGES.forEach(msg => msg.new = false);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}, },
/*LANG*/"Delete all messages" : () => { /*LANG*/"Delete all messages" : () => {
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => { E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
if (isYes) { if (isYes) {
MESSAGES = []; MESSAGES = [];
} }
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}); });
}, },
}); });
} }
function showMessage(msgid) { function showMessage(msgid) {
var msg = MESSAGES.find(m=>m.id==msgid); var msg = MESSAGES.find(m=>m.id==msgid);
if (updateLabelsInterval) { if (updateLabelsInterval) {
clearInterval(updateLabelsInterval); clearInterval(updateLabelsInterval);
updateLabelsInterval=undefined; updateLabelsInterval=undefined;
} }
if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); // go home if no message found if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); // go home if no message found
if (msg.id=="music") { if (msg.id=="music") {
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
return showMusicMessage(msg); return showMusicMessage(msg);
} }
if (msg.src=="Maps") { if (msg.src=="Maps") {
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
return showMapMessage(msg); return showMapMessage(msg);
} }
active = "message"; active = "message";
// Normal text message display // Normal text message display
var title=msg.title, titleFont = fontLarge, lines; var title=msg.title, titleFont = fontLarge, lines;
var body=msg.body, bodyFont = fontLarge; var body=msg.body, bodyFont = fontLarge;
// If no body, use the title text instead... // If no body, use the title text instead...
if (body===undefined) { if (body===undefined) {
body = title; body = title;
title = undefined; title = undefined;
} }
if (title) { if (title) {
var w = g.getWidth()-48; var w = g.getWidth()-48;
if (g.setFont(titleFont).stringWidth(title) > w) { if (g.setFont(titleFont).stringWidth(title) > w) {
titleFont = fontBig; titleFont = fontBig;
if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w) if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w)
titleFont = fontMedium; titleFont = fontMedium;
} }
if (g.setFont(titleFont).stringWidth(title) > w) { if (g.setFont(titleFont).stringWidth(title) > w) {
lines = g.wrapString(title, w); lines = g.wrapString(title, w);
title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n"); title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
} }
} }
// If body of message is only two lines long w/ large font, use large font. // If body of message is only two lines long w/ large font, use large font.
if (body) { if (body) {
var w = g.getWidth()-10; var w = g.getWidth()-10;
if (g.setFont(bodyFont).stringWidth(body) > w * 2) { if (g.setFont(bodyFont).stringWidth(body) > w * 2) {
bodyFont = fontBig; bodyFont = fontBig;
if (settings.fontSize!=1 && g.setFont(bodyFont).stringWidth(body) > w * 3) if (settings.fontSize!=1 && g.setFont(bodyFont).stringWidth(body) > w * 3)
bodyFont = fontMedium; bodyFont = fontMedium;
} }
if (g.setFont(bodyFont).stringWidth(body) > w) { if (g.setFont(bodyFont).stringWidth(body) > w) {
lines = g.setFont(bodyFont).wrapString(msg.body, w); lines = g.setFont(bodyFont).wrapString(msg.body, w);
var maxLines = Math.floor((g.getHeight()-110) / g.getFontHeight()); var maxLines = Math.floor((g.getHeight()-110) / g.getFontHeight());
body = (lines.length>maxLines) ? lines.slice(0,maxLines).join("\n")+"..." : lines.join("\n"); body = (lines.length>maxLines) ? lines.slice(0,maxLines).join("\n")+"..." : lines.join("\n");
} }
} }
function goBack() { function goBack() {
layout = undefined; layout = undefined;
msg.new = false; // read mail msg.new = false; // read mail
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
} }
var buttons = [ var buttons = [
]; ];
if (msg.positive) { if (msg.positive) {
buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{ buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
msg.new = false; msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,true); Bangle.messageResponse(msg,true);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}}); }});
} }
if (msg.negative) { if (msg.negative) {
if (buttons.length) buttons.push({width:32}); // nasty hack... if (buttons.length) buttons.push({width:32}); // nasty hack...
buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{ buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
msg.new = false; msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,false); Bangle.messageResponse(msg,false);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}}); }});
} }
layout = new Layout({ type:"v", c: [ layout = new Layout({ type:"v", c: [
{type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [ {type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [
{ type:"v", fillx:1, c: [ { type:"v", fillx:1, c: [
{type:"txt", font:fontSmall, label:msg.src||/*LANG*/"Message", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2, halign:1 }, {type:"txt", font:fontSmall, label:msg.src||/*LANG*/"Message", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2, halign:1 },
title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{}, title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
]}, ]},
{ type:"btn", { type:"btn",
src:require("messageicons").getImage(msg), src:require("messageicons").getImage(msg),
col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}), col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
pad: 3, cb:()=>{ pad: 3, cb:()=>{
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
showMessageSettings(msg); showMessageSettings(msg);
} }
}, },
]}, ]},
{type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{ {type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
// allow tapping to show a larger version // allow tapping to show a larger version
showMessageScroller(msg); showMessageScroller(msg);
} }, } },
{type:"h",fillx:1, c: buttons} {type:"h",fillx:1, c: buttons}
]},{back:goBack}); ]},{back:goBack});
g.reset().clearRect(Bangle.appRect); g.reset().clearRect(Bangle.appRect);
layout.render(); layout.render();
} }
@ -357,89 +357,89 @@ function showMessage(msgid) {
} }
*/ */
function checkMessages(options) { function checkMessages(options) {
options=options||{}; options=options||{};
// If no messages, just show 'no messages' and return // If no messages, just show 'no messages' and return
if (!MESSAGES.length) { if (!MESSAGES.length) {
if (!options.clockIfNoMsg) return E.showPrompt(/*LANG*/"No Messages",{ if (!options.clockIfNoMsg) return E.showPrompt(/*LANG*/"No Messages",{
title:/*LANG*/"Messages", title:/*LANG*/"Messages",
img:require("heatshrink").decompress(atob("kkk4UBrkc/4AC/tEqtACQkBqtUDg0VqAIGgoZFDYQIIM1sD1QAD4AIBhnqA4WrmAIBhc6BAWs8AIBhXOBAWz0AIC2YIC5wID1gkB1c6BAYFBEQPqBAYXBEQOqBAnDAIQaEnkAngaEEAPDFgo+IKA5iIOhCGIAFb7RqAIGgtUBA0VqobFgNVA")), img:require("heatshrink").decompress(atob("kkk4UBrkc/4AC/tEqtACQkBqtUDg0VqAIGgoZFDYQIIM1sD1QAD4AIBhnqA4WrmAIBhc6BAWs8AIBhXOBAWz0AIC2YIC5wID1gkB1c6BAYFBEQPqBAYXBEQOqBAnDAIQaEnkAngaEEAPDFgo+IKA5iIOhCGIAFb7RqAIGgtUBA0VqobFgNVA")),
buttons : {/*LANG*/"Ok":1} buttons : {/*LANG*/"Ok":1}
}).then(() => { load() }); }).then(() => { load() });
return load(); return load();
} }
// we have >0 messages // we have >0 messages
var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music"); var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music");
// If we have a new message, show it // If we have a new message, show it
if (options.showMsgIfUnread && newMessages.length) { if (options.showMsgIfUnread && newMessages.length) {
delete newMessages[0].show; // stop us getting stuck here if we're called a second time delete newMessages[0].show; // stop us getting stuck here if we're called a second time
showMessage(newMessages[0].id); showMessage(newMessages[0].id);
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern // buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
if (global.BUZZ_ON_NEW_MESSAGE) { if (global.BUZZ_ON_NEW_MESSAGE) {
// this is set if we entered the messages app by loading `messagegui.new.js` // this is set if we entered the messages app by loading `messagegui.new.js`
// ... but only buzz the first time we view a new message // ... but only buzz the first time we view a new message
global.BUZZ_ON_NEW_MESSAGE = false; global.BUZZ_ON_NEW_MESSAGE = false;
// messages.buzz respects quiet mode - no need to check here // messages.buzz respects quiet mode - no need to check here
require("messages").buzz(newMessages[0].src); require("messages").buzz(newMessages[0].src);
} }
return; return;
} }
// no new messages: show playing music? Only if we have playing music, or state=="show" (set by messagesmusic) // no new messages: show playing music? Only if we have playing music, or state=="show" (set by messagesmusic)
if (options.openMusic && MESSAGES.some(m=>m.id=="music" && ((m.track && m.state=="play") || m.state=="show"))) if (options.openMusic && MESSAGES.some(m=>m.id=="music" && ((m.track && m.state=="play") || m.state=="show")))
return showMessage('music'); return showMessage('music');
// no new messages - go to clock? // no new messages - go to clock?
if (options.clockIfAllRead && newMessages.length==0) if (options.clockIfAllRead && newMessages.length==0)
return load(); return load();
active = "main"; active = "main";
// Otherwise show a menu // Otherwise show a menu
E.showScroller({ E.showScroller({
h : 48, h : 48,
c : Math.max(MESSAGES.length,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11) c : Math.max(MESSAGES.length,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11)
draw : function(idx, r) {"ram" draw : function(idx, r) {"ram"
var msg = MESSAGES[idx]; var msg = MESSAGES[idx];
if (msg && msg.new) g.setBgColor(g.theme.bgH).setColor(g.theme.fgH); if (msg && msg.new) g.setBgColor(g.theme.bgH).setColor(g.theme.fgH);
else g.setBgColor(g.theme.bg).setColor(g.theme.fg); else g.setBgColor(g.theme.bg).setColor(g.theme.fg);
g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h); g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
if (!msg) return; if (!msg) return;
var x = r.x+2, title = msg.title, body = msg.body; var x = r.x+2, title = msg.title, body = msg.body;
var img = require("messageicons").getImage(msg); var img = require("messageicons").getImage(msg);
if (msg.id=="music") { if (msg.id=="music") {
title = msg.artist || /*LANG*/"Music"; title = msg.artist || /*LANG*/"Music";
body = msg.track; body = msg.track;
} }
if (img) { if (img) {
var fg = g.getColor(), var fg = g.getColor(),
col = require("messageicons").getColor(msg, {settings:settings, default:fg}); col = require("messageicons").getColor(msg, {settings:settings, default:fg});
g.setColor(col).drawImage(img, x+24, r.y+24, {rotate:0}) // force centering g.setColor(col).drawImage(img, x+24, r.y+24, {rotate:0}) // force centering
.setColor(fg); // only color the icon .setColor(fg); // only color the icon
x += 50; x += 50;
} }
var m = msg.title+"\n"+msg.body, longBody=false; var m = msg.title+"\n"+msg.body, longBody=false;
if (title) g.setFontAlign(-1,-1).setFont(fontBig).drawString(title, x,r.y+2); if (title) g.setFontAlign(-1,-1).setFont(fontBig).drawString(title, x,r.y+2);
if (body) { if (body) {
g.setFontAlign(-1,-1).setFont("6x8"); g.setFontAlign(-1,-1).setFont("6x8");
var l = g.wrapString(body, r.w-(x+14)); var l = g.wrapString(body, r.w-(x+14));
if (l.length>3) { if (l.length>3) {
l = l.slice(0,3); l = l.slice(0,3);
l[l.length-1]+="..."; l[l.length-1]+="...";
} }
longBody = l.length>2; longBody = l.length>2;
g.drawString(l.join("\n"), x+10,r.y+20); g.drawString(l.join("\n"), x+10,r.y+20);
} }
if (!longBody && msg.src) g.setFontAlign(1,1).setFont("6x8").drawString(msg.src, r.x+r.w-2, r.y+r.h-2); if (!longBody && msg.src) g.setFontAlign(1,1).setFont("6x8").drawString(msg.src, r.x+r.w-2, r.y+r.h-2);
g.setColor("#888").fillRect(r.x,r.y+r.h-1,r.x+r.w-1,r.y+r.h-1); // dividing line between items g.setColor("#888").fillRect(r.x,r.y+r.h-1,r.x+r.w-1,r.y+r.h-1); // dividing line between items
}, },
select : idx => showMessage(MESSAGES[idx].id), select : idx => showMessage(MESSAGES[idx].id),
back : () => load() back : () => load()
}); });
} }
function cancelReloadTimeout() { function cancelReloadTimeout() {
if (!unreadTimeout) return; if (!unreadTimeout) return;
clearTimeout(unreadTimeout); clearTimeout(unreadTimeout);
unreadTimeout = undefined; unreadTimeout = undefined;
} }
g.clear(); g.clear();
@ -449,12 +449,12 @@ require("messages").toggleWidget(false);
Bangle.drawWidgets(); Bangle.drawWidgets();
setTimeout(() => { setTimeout(() => {
if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60; if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60;
if (settings.unreadTimeout) if (settings.unreadTimeout)
unreadTimeout = setTimeout(load, settings.unreadTimeout*1000); unreadTimeout = setTimeout(load, settings.unreadTimeout*1000);
// only openMusic on launch if music is new, or state=="show" (set by messagesmusic) // only openMusic on launch if music is new, or state=="show" (set by messagesmusic)
var musicMsg = MESSAGES.find(m => m.id === "music"); var musicMsg = MESSAGES.find(m => m.id === "music");
checkMessages({ checkMessages({
clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1, clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1,
openMusic: ((musicMsg&&musicMsg.new) && settings.openMusic) || (musicMsg&&musicMsg.state=="show") }); openMusic: ((musicMsg&&musicMsg.new) && settings.openMusic) || (musicMsg&&musicMsg.state=="show") });
}, 10); // if checkMessages wants to 'load', do that }, 10); // if checkMessages wants to 'load', do that

Loading…
Cancel
Save