more clean up
parent
d93e26be6b
commit
5953a99ac6
|
|
@ -1,3 +1,4 @@
|
||||||
|
{
|
||||||
let options = {
|
let options = {
|
||||||
srcFont: "6x8",
|
srcFont: "6x8",
|
||||||
titleFont: "12x20",
|
titleFont: "12x20",
|
||||||
|
|
@ -231,3 +232,4 @@ module.exports.HeaderBox = HeaderBox;
|
||||||
module.exports.MessageBox = MessageBox;
|
module.exports.MessageBox = MessageBox;
|
||||||
module.exports.setOptions = setOptions;
|
module.exports.setOptions = setOptions;
|
||||||
module.exports.setClipRect = setClipRect;
|
module.exports.setClipRect = setClipRect;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,6 @@ let alarm;
|
||||||
let map;
|
let map;
|
||||||
let music;
|
let music;
|
||||||
|
|
||||||
let setActive = function(newActive) {
|
|
||||||
if (!newActive) return;
|
|
||||||
if (active && !previous.includes(active) && newActive !== active) previous.push(active);
|
|
||||||
active = newActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
let setListener = function(event, callback) {
|
let setListener = function(event, callback) {
|
||||||
if (!event || !callback) return;
|
if (!event || !callback) return;
|
||||||
events[event] = callback;
|
events[event] = callback;
|
||||||
|
|
@ -55,6 +49,53 @@ let clearTimeouts = function() {
|
||||||
for (let t in timeouts) clearTimeout(timeouts[t]);
|
for (let t in timeouts) clearTimeout(timeouts[t]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let setActive = function(newActive) {
|
||||||
|
if (!newActive) return;
|
||||||
|
if (active && !previous.includes(active) && newActive !== active) previous.push(active);
|
||||||
|
active = newActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
let setBusy = function() {
|
||||||
|
idle = false;
|
||||||
|
if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
|
||||||
|
timeouts["idleTimer"] = undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
let goBack = function(timedOut) {
|
||||||
|
idle = true;
|
||||||
|
if (buzzing) require("messages").stopBuzz();
|
||||||
|
let backTo;
|
||||||
|
if (previous && previous.length) {
|
||||||
|
backTo = previous.pop();
|
||||||
|
clearTimeouts();
|
||||||
|
} else {
|
||||||
|
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
||||||
|
require("messages").write(Bangle.MESSAGES);
|
||||||
|
cleanup = _cleanup;
|
||||||
|
cleanup();
|
||||||
|
Bangle.showClock();
|
||||||
|
}
|
||||||
|
switch (backTo) {
|
||||||
|
case "call": return showCall();
|
||||||
|
case "map": return showMap();
|
||||||
|
case "music": return showMusic();
|
||||||
|
case "alarm": return showAlarm();
|
||||||
|
case "text": return showText(textId);
|
||||||
|
}
|
||||||
|
}; // goBack
|
||||||
|
|
||||||
|
let 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");
|
||||||
|
let newUnhandledTexts = Bangle.MESSAGES.filter(m => m.new && !m.handled);
|
||||||
|
let newHandledTexts = Bangle.MESSAGES.filter(m => m.new && m.handled);
|
||||||
|
let otherTexts = Bangle.MESSAGES.filter(m => !m.new);
|
||||||
|
Bangle.MESSAGES = [].concat(newUnhandledTexts, newHandledTexts, otherTexts);
|
||||||
|
};
|
||||||
|
|
||||||
let showNoMessages = function() {
|
let showNoMessages = function() {
|
||||||
g.reset().clear();
|
g.reset().clear();
|
||||||
g.setFont("12x20").setFontAlign(0,0);
|
g.setFont("12x20").setFontAlign(0,0);
|
||||||
|
|
@ -69,6 +110,19 @@ let showNoMessages = function() {
|
||||||
goBack();
|
goBack();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let showMessage = function(id) {
|
||||||
|
if (call) {setActive("call"); return showCall();}
|
||||||
|
else if (alarm) {setActive("alarm"); return showAlarm();}
|
||||||
|
else if (map) {setActive("map"); return showMap();}
|
||||||
|
else if (music) {setActive("music"); return showMusic();}
|
||||||
|
else if (Bangle.MESSAGES.length){
|
||||||
|
Bangle.MESSAGES.every(m => m.handled = true); // set all text messages as handled
|
||||||
|
setActive("text");
|
||||||
|
return showText(id);
|
||||||
|
}
|
||||||
|
else goBack();
|
||||||
|
};
|
||||||
|
|
||||||
let showMusic = function() {
|
let showMusic = function() {
|
||||||
active = "music";
|
active = "music";
|
||||||
|
|
||||||
|
|
@ -531,7 +585,7 @@ let showText = function(id) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let leftHandler = function(e) {
|
let leftHandler = function(e) {
|
||||||
let msgBox = msgBoxes[messageNum];
|
//let msgBox = msgBoxes[messageNum];
|
||||||
switching = true;
|
switching = true;
|
||||||
animateToLeft().then(() => {
|
animateToLeft().then(() => {
|
||||||
g.setBgColor(g.theme.bg);
|
g.setBgColor(g.theme.bg);
|
||||||
|
|
@ -542,7 +596,7 @@ let showText = function(id) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let rightHandler = function(e) {
|
let rightHandler = function(e) {
|
||||||
let msgBox = msgBoxes[messageNum];
|
// let msgBox = msgBoxes[messageNum];
|
||||||
switching = true;
|
switching = true;
|
||||||
animateToRight().then(() => {
|
animateToRight().then(() => {
|
||||||
g.setBgColor(g.theme.bg);
|
g.setBgColor(g.theme.bg);
|
||||||
|
|
@ -584,51 +638,21 @@ let checkForNewMessages = function(idleTime) {
|
||||||
}, idleTime);
|
}, idleTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
let setBusy = function() {
|
|
||||||
idle = false;
|
|
||||||
if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
|
|
||||||
timeouts["idleTimer"] = undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
let goBack = function(timedOut) {
|
|
||||||
idle = true;
|
|
||||||
if (buzzing) require("messages").stopBuzz();
|
|
||||||
let backTo;
|
|
||||||
if (previous && previous.length) {
|
|
||||||
backTo = previous.pop();
|
|
||||||
clearTimeouts();
|
|
||||||
} else {
|
|
||||||
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
|
||||||
require("messages").write(Bangle.MESSAGES);
|
|
||||||
cleanup = _cleanup;
|
|
||||||
cleanup();
|
|
||||||
Bangle.showClock();
|
|
||||||
}
|
|
||||||
switch (backTo) {
|
|
||||||
case "call": return showCall();
|
|
||||||
case "map": return showMap();
|
|
||||||
case "music": return showMusic();
|
|
||||||
case "alarm": return showAlarm();
|
|
||||||
case "text": return showText(textId);
|
|
||||||
}
|
|
||||||
}; // goBack
|
|
||||||
|
|
||||||
let newMessage = (type, msg) => {
|
let newMessage = (type, msg) => {
|
||||||
filterMessages();
|
filterMessages();
|
||||||
msgId = msg.id;
|
msgId = msg.id;
|
||||||
|
if (type === "call" && msg.t === "remove") require("messages").stopBuzz();
|
||||||
if (type === "text" && msg.t === "remove") {
|
if (type === "text" && msg.t === "remove") {
|
||||||
if (active === "text" && buzzing && msg.id === textId) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
|
if (active === "text" && buzzing && msg.id === textId) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
|
||||||
|
|
||||||
let msgIdx = Bangle.MESSAGES.findIndex(m => m.id === msg.id);
|
let msgIdx = Bangle.MESSAGES.findIndex(m => m.id === msg.id);
|
||||||
if (Bangle.MESSAGES.length > 1 && msg.id === msgId) {
|
if (Bangle.MESSAGES.length > 1 && msg.id === msgId) {
|
||||||
if (msgIdx === 0) msgId = Bangle.MESSAGES[msgIdx+1].id;
|
if (msgIdx === 0) msgId = Bangle.MESSAGES[msgIdx+1].id;
|
||||||
else if (msgIdx === Bangle.MESSAGES.length - 1) msgId = Bangle.MESSAGES[msgIdx-1].id;
|
else if (msgIdx === Bangle.MESSAGES.length - 1) msgId = Bangle.MESSAGES[msgIdx-1].id;
|
||||||
else msgId = textId;
|
else msgId = textId;
|
||||||
|
|
||||||
} else if (Bangle.MESSAGES.length === 1) msgId = 0;
|
} else if (Bangle.MESSAGES.length === 1) msgId = 0;
|
||||||
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id); // remove
|
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id); // remove
|
||||||
require("messages").write(Bangle.MESSAGES); // write removal to flash
|
require("messages").write(Bangle.MESSAGES); // write removal to flash
|
||||||
if (textId === msg.id) textId = 0; // just removed the message we were viewing
|
if (textId === msg.id) msgId = 0; // just removed the message we were viewing
|
||||||
}
|
}
|
||||||
if (active === "text" && !idle) {
|
if (active === "text" && !idle) {
|
||||||
haveNewMessage = true;
|
haveNewMessage = true;
|
||||||
|
|
@ -638,31 +662,6 @@ let newMessage = (type, msg) => {
|
||||||
};
|
};
|
||||||
setListener("breakingnews", newMessage);
|
setListener("breakingnews", newMessage);
|
||||||
|
|
||||||
let 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");
|
|
||||||
let newUnhandledTexts = Bangle.MESSAGES.filter(m => m.new && !m.handled);
|
|
||||||
let newHandledTexts = Bangle.MESSAGES.filter(m => m.new && m.handled);
|
|
||||||
let otherTexts = Bangle.MESSAGES.filter(m => !m.new && !m.handled);
|
|
||||||
Bangle.MESSAGES = [].concat(newUnhandledTexts, newHandledTexts, otherTexts);
|
|
||||||
};
|
|
||||||
|
|
||||||
let showMessage = function(id) {
|
|
||||||
if (call) {setActive("call"); return showCall();}
|
|
||||||
else if (alarm) {setActive("alarm"); return showAlarm();}
|
|
||||||
else if (map) {setActive("map"); return showMap();}
|
|
||||||
else if (music) {setActive("music"); return showMusic();}
|
|
||||||
else if (Bangle.MESSAGES.length){
|
|
||||||
Bangle.MESSAGES.every(m => m.handled = true); // set all text messages as handled
|
|
||||||
setActive("text");
|
|
||||||
return showText(id);
|
|
||||||
}
|
|
||||||
else goBack();
|
|
||||||
};
|
|
||||||
|
|
||||||
// entry point
|
// entry point
|
||||||
saveMessages = function() {
|
saveMessages = function() {
|
||||||
require("messages").write(Bangle.MESSAGES);
|
require("messages").write(Bangle.MESSAGES);
|
||||||
|
|
@ -680,13 +679,13 @@ if (!Bangle.MESSAGES.length) showNoMessages();
|
||||||
|
|
||||||
if (Bangle.notify) { // notification arrived that opened the app. This is set in messagecenter.notify.js
|
if (Bangle.notify) { // notification arrived that opened the app. This is set in messagecenter.notify.js
|
||||||
let msg = Bangle.MESSAGES[0];
|
let msg = Bangle.MESSAGES[0];
|
||||||
if (msg.id !== "call" && msg.t !== "modify") {
|
if (msg.t !== "delete") {
|
||||||
buzzing = true;
|
buzzing = true;
|
||||||
require("messages").buzz(msg.src);
|
require("messages").buzz(msg.src);
|
||||||
delete Bangle.notify;
|
delete Bangle.notify;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msgId = Bangle.MESSAGES.length ? Bangle.MESSAGES[0].id : 0;
|
||||||
filterMessages();
|
filterMessages();
|
||||||
textId = Bangle.MESSAGES.length ? Bangle.MESSAGES[0].id : 0;
|
showMessage(msgId);
|
||||||
showMessage(textId);
|
|
||||||
//}
|
//}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
{
|
||||||
const loadWillReset = () => Bangle.load === load || !Bangle.uiRemove;
|
const loadWillReset = () => Bangle.load === load || !Bangle.uiRemove;
|
||||||
|
|
||||||
exports.messageListener = function(type, msg) {
|
exports.messageListener = function(type, msg) {
|
||||||
|
|
@ -7,20 +8,13 @@ exports.messageListener = function(type, msg) {
|
||||||
if (!Bangle.MESSAGES || !Bangle.MESSAGES.length) Bangle.MESSAGES = require("messages").getMessages(msg);
|
if (!Bangle.MESSAGES || !Bangle.MESSAGES.length) Bangle.MESSAGES = require("messages").getMessages(msg);
|
||||||
msg.show = true;
|
msg.show = true;
|
||||||
msg.type = type;
|
msg.type = type;
|
||||||
if (msg.id === "call" && msg.t === "remove") {
|
|
||||||
msg.t = "modify"; // not sure why messages module puts everything as remove except for "incoming"
|
|
||||||
msg.new = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.t === "add") {
|
if (msg.t === "add") {
|
||||||
require("messages").apply(msg, Bangle.MESSAGES);
|
require("messages").apply(msg, Bangle.MESSAGES);
|
||||||
} else if (msg.t === "modify") {
|
} else if (msg.t === "modify" || type === "call") {
|
||||||
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id); // remove old version of message
|
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id); // remove old version of message
|
||||||
Bangle.MESSAGES.unshift(msg); // put modified message at start of list
|
Bangle.MESSAGES.unshift(msg); // put modified message at start of list
|
||||||
} // else {
|
}
|
||||||
// Bangle.MESSAGES.unshift(msg); // add new message to start of list
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!inApp) {
|
if (!inApp) {
|
||||||
if (msg.t === "remove") {
|
if (msg.t === "remove") {
|
||||||
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id);
|
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id);
|
||||||
|
|
@ -38,3 +32,4 @@ exports.messageListener = function(type, msg) {
|
||||||
exports.open = function(msg) {
|
exports.open = function(msg) {
|
||||||
Bangle.load("messagecenter.app.js");
|
Bangle.load("messagecenter.app.js");
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue