648 lines
19 KiB
JavaScript
648 lines
19 KiB
JavaScript
//{
|
|
|
|
//let settings = require('Storage').readJSON("messages.settings.json", true) || {};
|
|
//const settings = () => require("messagegui").settings();
|
|
const fontTiny = "6x8"; // fixed size, don't use this for important things
|
|
let fontNormal;
|
|
// setFont() is also called after we close the settings screen
|
|
// const setFont = function() {
|
|
// const fontSize = settings().fontSize;
|
|
// if (fontSize===0) // small
|
|
// fontNormal = g.getFonts().includes("6x15") ? "6x15" : "6x8:2";
|
|
// else if (fontSize===2) // large
|
|
// fontNormal = g.getFonts().includes("6x15") ? "6x15:2" : "6x8:4";
|
|
// else // medium
|
|
// fontNormal = g.getFonts().includes("12x20") ? "12x20" : "6x8:3";
|
|
// };
|
|
// setFont();
|
|
|
|
let idle = false;
|
|
let haveNewMessage = false;
|
|
let active;
|
|
let buzzing;
|
|
let events = {};
|
|
let timeouts = {};
|
|
let cleanup = function() {}; // we don't want cleanup function to do anything until we actually need it
|
|
let previous = [];
|
|
let msgIdx;
|
|
let call;
|
|
let alarm;
|
|
let map;
|
|
let music;
|
|
|
|
const setActive = function(newActive) {
|
|
if (!newActive) return;
|
|
if (active && !previous.includes(active) && newActive !== active) previous.push(active);
|
|
active = newActive;
|
|
console.log(previous);
|
|
}
|
|
|
|
const setListener = function(event, callback) {
|
|
if (!event || !callback) return;
|
|
events[event] = callback;
|
|
Bangle.on(event, events[event]);
|
|
};
|
|
|
|
const _cleanup = function() {
|
|
for (let e in events) if (e) Bangle.removeListener(e, events[e]);
|
|
for (let t in timeouts) if (timeouts[t]) clearTimeout(timeouts[t]);
|
|
require("messages").stopBuzz();
|
|
};
|
|
|
|
const clearTimeouts = function() {
|
|
for (let t in timeouts) if (timeouts[t]) clearTimeout(timeouts[t]);
|
|
};
|
|
|
|
const showNoMessages = function() {
|
|
|
|
g.reset().clear();
|
|
g.setFont("12x20").setFontAlign(0,0);
|
|
g.drawString("No Messages!", Bangle.appRect.x + (Bangle.appRect.w / 2), Bangle.appRect.y + (Bangle.appRect.h / 2));
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
btn: goBack(),
|
|
remove: cleanup
|
|
});
|
|
};
|
|
|
|
const showMusic = function(music) {
|
|
active = "music";
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
btn: goBack(),
|
|
remove: cleanup
|
|
});
|
|
};
|
|
|
|
const showMap = function(map) {
|
|
active = "map";
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
btn: goBack(),
|
|
remove: cleanup
|
|
});
|
|
};
|
|
|
|
const showAlarm = function(alarm) {
|
|
active = "alarm";
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
btn: goBack(),
|
|
remove: cleanup
|
|
});
|
|
};
|
|
|
|
const showCall = function(call) {
|
|
Bangle.setUI(); // clear from previous
|
|
const HeaderBox = new require("messagebox").HeaderBox;
|
|
let header = new HeaderBox(call, Bangle.appRect);
|
|
g.reset().clear().setFont("12x20")
|
|
header.draw(Bangle.appRect);
|
|
let str = g.wrapString(JSON.stringify(call),g.getWidth()).join("\n");
|
|
g.drawString(str, 0, 60);
|
|
console.log("call: ", call);
|
|
|
|
const handler = function(e) {
|
|
console.log(e);
|
|
};
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
drag: handler,
|
|
btn: goBack,
|
|
remove: cleanup
|
|
});
|
|
};
|
|
|
|
const showText = function(messageNum) {
|
|
g.reset().clear();
|
|
if (!Bangle.MESSAGES.length) return goBack(); // no messages
|
|
setBusy(); // busy until everything is set up
|
|
let showAll = false;
|
|
if (messageNum === undefined) {messageNum = 0; showAll = true;}
|
|
else if (messageNum >= Bangle.MESSAGES.length - 1) messageNum = Bangle.MESSAGES.length - 1;
|
|
Bangle.setUI(); // make sure to clear setUI from anything previous
|
|
let switching = false;
|
|
let MessageBox = require("messagebox").MessageBox;
|
|
require("messagebox").setOptions({fh: 20});
|
|
const step = 42;
|
|
const delay = 30;
|
|
const swipeThreshold = 20;
|
|
let mode = "scroll"; // one of "scroll", "next", "prev" (switch to next/prev message), "swipe" (swipe to delete or archive)
|
|
msgIdx = messageNum; // global message index
|
|
// TODO we might have to append array of (m.show && !m.new) to array of m.new so that all new messages are at the beginning of list
|
|
let messageList = showAll ? Bangle.MESSAGES : Bangle.MESSAGES.filter(m => m.new || m.show);
|
|
if (!messageList.length) return goBack();
|
|
|
|
// Bangle.setLocked(false); // TODO make as option
|
|
// Bangle.setLCDPower(true); // TODO make as option
|
|
|
|
let msgBoxes = [];
|
|
let i = 0;
|
|
for (let msg of messageList) {
|
|
msgBoxes[i] = new MessageBox(msg);
|
|
if (i === messageNum - 1) msgBoxes[i].yOffset = MessageBox.prototype.prevOffset;
|
|
else if (i === messageNum) {
|
|
msgBoxes[i].yOffset = 0;
|
|
msgBoxes[i].draw();
|
|
}
|
|
else if ( i === messageNum + 1) msgBoxes[i].yOffset = MessageBox.prototype.nextOffset;
|
|
i++;
|
|
}
|
|
|
|
const drawFooter = function() {
|
|
let fh = 20; // footer height
|
|
// left hint: swipe from left for main menu
|
|
g.reset().setBgColor(g.theme.bg2).clearRect(Bangle.appRect.x, Bangle.appRect.y2-fh, Bangle.appRect.x2, Bangle.appRect.y2)
|
|
.setFont("6x15") // TODO make as option
|
|
.setFontAlign(-1, 1) // bottom left
|
|
.drawString(
|
|
//"\0"+atob("CAiBAEgkEgkSJEgA"), // >>
|
|
">>",
|
|
Bangle.appRect.x + 1, Bangle.appRect.y2
|
|
);
|
|
// center message count+hints: swipe up/down for next/prev message
|
|
const footer = ` ${messageNum + 1}/${msgBoxes.length} `;
|
|
const fw = g.stringWidth(footer);
|
|
g.setFontAlign(0, 1); // bottom center
|
|
g.drawString(footer, Bangle.appRect.x+Bangle.appRect.w/2, Bangle.appRect.y2);
|
|
if (messageNum < Bangle.MESSAGES.length - 1 && msgBoxes[messageNum].bottom)
|
|
g.drawString("\0"+atob("CAiBAABBIhRJIhQI"), Bangle.appRect.x+Bangle.appRect.w/2-fw/2 - 20, Bangle.appRect.y2); // v swipe to next
|
|
if (messageNum > 0 && msgBoxes[messageNum].top)
|
|
g.drawString("\0"+atob("CAiBABAoRJIoRIIA"), Bangle.appRect.x+Bangle.appRect.w/2+fw/2 + 20, Bangle.appRect.y2); // ^ swipe to prev
|
|
// right hint: swipe from right for message actions
|
|
g.setFontAlign(1, 1) // bottom right
|
|
.drawString(
|
|
//"\0"+atob("CAiBABIkSJBIJBIA"), // <<
|
|
"<<",
|
|
Bangle.appRect.x2 - 1, Bangle.appRect.y2
|
|
);
|
|
};
|
|
|
|
const refresh = function() {
|
|
if (messageNum >= 0 && messageNum < msgBoxes.length) {
|
|
msgBoxes[messageNum].reset();
|
|
if (messageNum > 0) msgBoxes[messageNum - 1].reset(MessageBox.prototype.prevOffset);
|
|
if (messageNum < msgBoxes.length - 1) msgBoxes[messageNum + 1].reset(MessageBox.prototype.nextOffset);
|
|
}
|
|
};
|
|
|
|
const removeMessage = function() {
|
|
const removeAndReset = () => {
|
|
const id = msgBoxes[messageNum].msg.id;
|
|
const idx = Bangle.MESSAGES.findIndex(m => m.id === id);
|
|
Bangle.MESSAGES.splice(idx, 1); // remove from Bangle.MESSAGES
|
|
msgBoxes.splice(messageNum, 1); // remove from msgBoxes
|
|
if (!msgBoxes.length) {
|
|
Bangle.setUI();
|
|
return goBack(); // no more messages
|
|
}
|
|
if (messageNum === msgBoxes.length) {
|
|
messageNum--; // we removed the last message, go to previous message
|
|
msgIdx = messageNum; // update global message index
|
|
}
|
|
// otherwise messageNum is automatically the index of the next message now
|
|
refresh();
|
|
msgBoxes[messageNum].draw();
|
|
drawFooter();
|
|
};
|
|
if (messageNum < msgBoxes.length - 1) {
|
|
require("messagebox").setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.setBgColor(g.theme.bg).clear();
|
|
toNext(true).then(() => {
|
|
removeAndReset();
|
|
switching = false;
|
|
});
|
|
} else if (messageNum > 0) {
|
|
require("messagebox").setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.setBgColor(g.theme.bg).clear();
|
|
toPrev(true).then(() => {
|
|
removeAndReset();
|
|
switching = false;
|
|
});
|
|
} else {
|
|
removeAndReset();
|
|
}
|
|
};
|
|
|
|
const dismissOnPhone = function() {
|
|
return Bangle.messageResponse(msgBoxes[messageNum].msg, false); // false to dismiss, true to open on phone
|
|
};
|
|
|
|
const toNext = function(removeCurrent) {
|
|
if (removeCurrent == undefined) removeCurrent = false;
|
|
if (timeouts.animID){
|
|
clearTimeout(timeouts.animID);
|
|
timeouts.animID = undefined;
|
|
}
|
|
firstTouch = true;
|
|
return new Promise((resolve, _reject) => {
|
|
let multiplier = 1;
|
|
let animate = () => {
|
|
msgBoxes[messageNum].yOffset -= step * multiplier;
|
|
msgBoxes[messageNum + 1].yOffset -= step * multiplier;
|
|
if (msgBoxes[messageNum + 1].yOffset <= 0) {
|
|
if (!removeCurrent) {
|
|
if (messageNum < msgBoxes.length) {
|
|
messageNum++;
|
|
msgIdx = messageNum; // update global message index
|
|
refresh();
|
|
}
|
|
}
|
|
msgBoxes[messageNum].draw();
|
|
drawFooter();
|
|
return resolve();
|
|
} else {
|
|
msgBoxes[messageNum].draw();
|
|
msgBoxes[messageNum + 1].draw();
|
|
drawFooter();
|
|
multiplier *= 2;
|
|
timeouts.animID = setTimeout(animate, delay);
|
|
}
|
|
};
|
|
animate();
|
|
});
|
|
};
|
|
|
|
const toPrev = function(removeCurrent) {
|
|
if (removeCurrent == undefined) removeCurrent = false;
|
|
if (timeouts.animID){
|
|
clearTimeout(timeouts.animID);
|
|
timeouts.animID = undefined;
|
|
}
|
|
firstTouch = true;
|
|
return new Promise((resolve, _reject) => {
|
|
let multiplier = 1;
|
|
let animate = () => {
|
|
msgBoxes[messageNum].yOffset += step * multiplier;
|
|
msgBoxes[messageNum - 1].yOffset += step * multiplier;
|
|
if (msgBoxes[messageNum - 1].yOffset >= 0) {
|
|
if (!removeCurrent) {
|
|
if (messageNum > 0) {
|
|
messageNum--;
|
|
msgIdx = messageNum; // update global message index
|
|
refresh();
|
|
}
|
|
}
|
|
msgBoxes[messageNum].draw();
|
|
drawFooter();
|
|
return resolve();
|
|
} else {
|
|
msgBoxes[messageNum].draw();
|
|
msgBoxes[messageNum - 1].draw();
|
|
drawFooter();
|
|
multiplier *= 2;
|
|
timeouts.animID = setTimeout(animate, delay);
|
|
}
|
|
};
|
|
animate();
|
|
});
|
|
};
|
|
|
|
const drawLeftBackground = function() {
|
|
g.setBgColor(1, 0.5, 0); // red
|
|
g.setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.clearRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.setBgColor(g.theme.bg);
|
|
};
|
|
|
|
const drawRightBackground = function() {
|
|
g.setBgColor(0, 0.5, 1); // red
|
|
g.setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.clearRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
g.setBgColor(g.theme.bg);
|
|
};
|
|
|
|
const animateToLeft = function() {
|
|
if (timeouts.animID) {
|
|
clearTimeout(timeouts.animID);
|
|
timeouts.animID = undefined;
|
|
}
|
|
const endX = Bangle.appRect.x + (Bangle.appRect.w / 2);
|
|
const msgBox = msgBoxes[messageNum];
|
|
return new Promise((resolve, _reject) => {
|
|
let animate = () => {
|
|
msgBox.xOffset -= step;
|
|
drawLeftBackground();
|
|
if (msgBox.xOffset <= endX) {
|
|
return resolve();
|
|
} else {
|
|
msgBox.draw();
|
|
drawFooter();
|
|
timeouts.animID = setTimeout(animate, delay);
|
|
}
|
|
};
|
|
animate();
|
|
});
|
|
};
|
|
|
|
const animateToRight = function() {
|
|
if (timeouts.animID) {
|
|
clearTimeout(timeouts.animID);
|
|
timeouts.animID = undefined;
|
|
}
|
|
const endX = Bangle.appRect.x2 - (Bangle.appRect.w / 2);
|
|
const msgBox = msgBoxes[messageNum];
|
|
return new Promise((resolve, _reject) => {
|
|
let animate = () => {
|
|
msgBox.xOffset += step;
|
|
drawRightBackground();
|
|
if (msgBox.xOffset >= endX) {
|
|
return resolve();
|
|
} else {
|
|
msgBox.draw();
|
|
drawFooter();
|
|
timeouts.animID = setTimeout(animate, delay);
|
|
}
|
|
};
|
|
animate();
|
|
});
|
|
};
|
|
|
|
let firstTouch = true;
|
|
const handler = function(e) {
|
|
if (e.b === 0) {
|
|
firstTouch = true;
|
|
checkForNewMessages();
|
|
}
|
|
if (switching) return; // don't respond to touch while we are animating
|
|
if (firstTouch && e.b === 1) {
|
|
if (buzzing) {
|
|
require("messages").stopBuzz();
|
|
buzzing = false;
|
|
}
|
|
setBusy();
|
|
let idx = Bangle.MESSAGES.findIndex(m => m.id === msgBoxes[messageNum].msg.id); // TODO maybe we don't to do this check every time
|
|
if (idx >= 0) delete Bangle.MESSAGES[idx].new;
|
|
msgBoxes[messageNum].clearNew();
|
|
if (Math.abs(e.dy) > Math.abs(e.dx)) {
|
|
firstTouch = false;
|
|
if (e.dy > 0 && msgBoxes[messageNum].top) {
|
|
mode = "prev";
|
|
} else if (msgBoxes[messageNum].bottom) { // e.dy will be < 0 here
|
|
mode = "next";
|
|
} else {
|
|
mode = "scroll";
|
|
}
|
|
} else if (Math.abs(e.dx) > Math.abs(e.dy)) {
|
|
firstTouch = false;
|
|
if (e.dx < 0) {
|
|
mode = "left";
|
|
} else {
|
|
mode = "right";
|
|
}
|
|
} else {
|
|
mode = undefined;
|
|
return;
|
|
}
|
|
}
|
|
if (mode == "scroll") scrollHandler(e);
|
|
else if (mode == "left") leftHandler(e); // remove from phone and watch
|
|
else if (mode == "right") rightHandler(e); // remove from watch only
|
|
else if (mode == "next") nextHandler(e);
|
|
else if (mode == "prev") prevHandler(e);
|
|
};
|
|
|
|
const nextHandler = function(e) {
|
|
if (e.b == 0) {
|
|
}
|
|
if (messageNum == msgBoxes.length - 1) return; // already on last message
|
|
switching = true;
|
|
toNext().then(() => {
|
|
switching = false;
|
|
});
|
|
};
|
|
|
|
const prevHandler = function(e) {
|
|
if (e.b == 0) {
|
|
}
|
|
if (messageNum == 0) return; // already on first message
|
|
switching = true;
|
|
toPrev().then(() => {
|
|
switching = false;
|
|
});
|
|
};
|
|
|
|
const leftHandler = function(e) {
|
|
const msgBox = msgBoxes[messageNum];
|
|
if (e.b == 0) {
|
|
if (msgBox.xOffset > -swipeThreshold) {
|
|
msgBox.xOffset = 0;
|
|
msgBox.draw();
|
|
drawFooter();
|
|
} else {
|
|
switching = true;
|
|
animateToLeft().then(() => {
|
|
g.setBgColor(g.theme.bg);
|
|
dismissOnPhone();
|
|
removeMessage();
|
|
switching = false;
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
msgBox.xOffset += e.dx;
|
|
if (msgBox.xOffset > 0) msgBox.xOffset = 0;
|
|
drawLeftBackground();
|
|
msgBox.draw();
|
|
drawFooter();
|
|
};
|
|
|
|
const rightHandler = function(e) {
|
|
const msgBox = msgBoxes[messageNum];
|
|
if (e.b == 0) {
|
|
if (msgBox.xOffset < swipeThreshold) {
|
|
msgBox.xOffset = 0;
|
|
msgBox.draw();
|
|
drawFooter();
|
|
} else {
|
|
switching = true;
|
|
animateToRight().then(() => {
|
|
g.setBgColor(g.theme.bg);
|
|
removeMessage();
|
|
switching = false;
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
msgBox.xOffset += e.dx;
|
|
if (msgBox.xOffset < 0) msgBox.xOffset = 0;
|
|
drawRightBackground();
|
|
msgBox.draw();
|
|
drawFooter();
|
|
};
|
|
|
|
const scrollHandler = function(e) {
|
|
if (e.b === 0) {
|
|
}
|
|
msgBoxes[messageNum].scroll(e.dy);
|
|
};
|
|
|
|
Bangle.setUI({
|
|
mode: "custom",
|
|
drag: e => handler(e),
|
|
btn: _e => goBack(),
|
|
remove: cleanup
|
|
});
|
|
|
|
msgBoxes[messageNum].draw();
|
|
drawFooter();
|
|
checkForNewMessages();
|
|
}; // function showText
|
|
|
|
// Check for new messages, wait until there is no interaction for `idleTime` ms
|
|
const checkForNewMessages = function(idleTime) {
|
|
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
|
|
idle = false;
|
|
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
|
|
timeouts.idleTimer = setTimeout(() => {
|
|
if (haveNewMessage) {
|
|
haveNewMessage = false;
|
|
let idx = Bangle.MESSAGES.findIndex(m => !m.handled);
|
|
if (idx >= 0) {
|
|
for (let m of Bangle.MESSAGES) m.handled = true; // set all text messages as handled
|
|
setActive("text");
|
|
return showText(idx);
|
|
} else {
|
|
setActive("text");
|
|
return showText(msgIdx);
|
|
}
|
|
}
|
|
idle = true;
|
|
}, idleTime);
|
|
};
|
|
|
|
const setBusy = function() {
|
|
idle = false;
|
|
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
|
|
timeouts.idleTimer = undefined;
|
|
};
|
|
|
|
const goBack = function(timedOut) { // TODO do we want this as a stack or by priority?
|
|
idle = true;
|
|
if (buzzing) require("messages").stopBuzz();
|
|
let backTo;
|
|
if (previous && previous.length) backTo = previous.pop();
|
|
console.log("backTo = ", backTo);
|
|
switch (backTo) {
|
|
case "call": return showCall(call);
|
|
case "map": return showMap(map);
|
|
case "music": return showMusic(music);
|
|
case "alarm": return showAlarm(alarm);
|
|
case "text":
|
|
if (Bangle.MESSAGES.length) {
|
|
if (msgIdx < Bangle.MESSAGES.length) return showText(msgIdx);
|
|
else return showText(0);
|
|
}
|
|
default:
|
|
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
|
require("messages").write(Bangle.MESSAGES);
|
|
cleanup = _cleanup;
|
|
Bangle.showClock();
|
|
}
|
|
}; // function goBack
|
|
|
|
const newMessage = (type, msg) => {
|
|
filterMessages();
|
|
// if (!previous.includes(active) && type != active) previous.push(active);
|
|
switch (type) {
|
|
case "text":
|
|
if (msg.t === "remove") {
|
|
let idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id);
|
|
if (idx >= 0) Bangle.MESSAGES.splice(idx, 1); // remove 'remove' from Bangle.MESSAGES
|
|
idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id && m.t !== "remove");
|
|
if (active === "text" && buzzing && idx === msgIdx) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
|
|
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id);
|
|
require("messages").write(Bangle.MESSAGES); // write removal to flash
|
|
if (active === "text") {
|
|
if (idle) showText(msgIdx); // we are idle so updated messages right away
|
|
else haveNewMessage = true; // otherwise set new message flag and wait until idle
|
|
}
|
|
return;
|
|
}
|
|
let idx = Bangle.MESSAGES.findIndex(m => !m.handled);
|
|
if (idle) { // idle so show message right away
|
|
if (idx >= 0) {
|
|
for (let m of Bangle.MESSAGES) m.handled = true; // set all text messages as handled
|
|
setActive("text");
|
|
return showText(idx);
|
|
} else {
|
|
setActive("text")
|
|
return showText(msgIdx);
|
|
}
|
|
}
|
|
else haveNewMessage = true; // otherwise set new message flag and wait until idle
|
|
break;
|
|
|
|
case "call":
|
|
if (call && call.t === "remove") {call = undefined; goBack();}
|
|
if (call) {setActive("call"); showCall(call);}
|
|
break;
|
|
case "alarm":
|
|
if (alarm.new) {setActive("alarm"); showAlarm(alarm);}
|
|
break;
|
|
case "map":
|
|
if (map.new) {setActive("map"); showMap(map);}
|
|
break;
|
|
case "music":
|
|
if (music.new) {setActive("music"); showMusic(music);}
|
|
break;
|
|
}
|
|
};
|
|
setListener("breakingnews", newMessage);
|
|
|
|
const filterMessages = function() {
|
|
call = Bangle.MESSAGES.find(m => m.type === "call");
|
|
alarm = Bangle.MESSAGES.find(m => m.type === "alarm");
|
|
map = Bangle.MESSAGES.find(m => m.type === "map");
|
|
music = Bangle.MESSAGES.find(m => m.type === "music");
|
|
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.type === "text");
|
|
};
|
|
|
|
const showMessage = function() {
|
|
if (call) {setActive("call"); return showCall(call);}
|
|
else if (alarm && !alarm.handled) {setActive("alarm"); return showAlarm(alarm);}
|
|
else if (map && !map.handled) {setActive("map"); return showMap(map);}
|
|
else if (music && !music.handled) {setActive("music"); return showMusic(music);}
|
|
else {
|
|
idx = Bangle.MESSAGES.findIndex(m => !m.handled);
|
|
if (idx >= 0) {
|
|
for (let m of Bangle.MESSAGES) m.handled = true; // set all text messages as handled
|
|
setActive("text");
|
|
return showText(idx);
|
|
}
|
|
}
|
|
goBack();
|
|
};
|
|
|
|
// entry point
|
|
events.saveMessages = function() {
|
|
require("messages").write(Bangle.MESSAGES);
|
|
};
|
|
E.on("kill", events.saveMessages);
|
|
|
|
Bangle.loadWidgets();
|
|
require("widget_utils").hide();
|
|
|
|
if (!Bangle.MESSAGES || !Bangle.MESSAGES.length) {
|
|
Bangle.MESSAGES = require("messages").getMessages();
|
|
}
|
|
|
|
if (Bangle.notify) { // notification arrived that opened the app. This is set in messagecenter.notify.js
|
|
buzzing = true;
|
|
require("messages").buzz(Bangle.MESSAGES[0].src);
|
|
delete Bangle.notify;
|
|
filterMessages();
|
|
showMessage();
|
|
} else { // user opened the app
|
|
if (!Bangle.MESSAGES.length) showNoMessages();
|
|
else {
|
|
showText(); // show all messages
|
|
}
|
|
}
|
|
//}
|