2022-05-24 12:24:38 +00:00
|
|
|
(() => {
|
2022-09-24 13:50:20 +00:00
|
|
|
if ((require('Storage').readJSON("messages.settings.json", true) || {}).maxMessages===0) return;
|
2022-05-24 12:24:38 +00:00
|
|
|
|
2022-05-29 04:19:38 +00:00
|
|
|
function filterMessages(msgs) {
|
|
|
|
return msgs.filter(msg => msg.new && msg.id != "music")
|
2022-07-23 19:33:42 +00:00
|
|
|
.map(m => m.src) // we only need this for icon/color
|
2022-05-24 12:24:38 +00:00
|
|
|
.filter((msg, i, arr) => arr.findIndex(nmsg => msg.src == nmsg.src) == i);
|
|
|
|
}
|
|
|
|
|
2022-07-25 14:53:59 +00:00
|
|
|
WIDGETS["messages"]={area:"tl", width:0, draw:function(recall) {
|
2022-03-09 13:39:19 +00:00
|
|
|
// If we had a setTimeout queued from the last time we were called, remove it
|
|
|
|
if (WIDGETS["messages"].i) {
|
|
|
|
clearTimeout(WIDGETS["messages"].i);
|
|
|
|
delete WIDGETS["messages"].i;
|
|
|
|
}
|
2021-12-09 19:54:39 +00:00
|
|
|
Bangle.removeListener('touch', this.touch);
|
2021-10-22 10:47:23 +00:00
|
|
|
if (!this.width) return;
|
|
|
|
var c = (Date.now()-this.t)/1000;
|
2022-07-15 11:10:52 +00:00
|
|
|
let settings = Object.assign({flash:true, maxMessages:3, repeat:4, vibrateTimeout:60},require('Storage').readJSON("messages.settings.json", true) || {});
|
2022-04-06 23:30:39 +00:00
|
|
|
if (recall !== true || settings.flash) {
|
2022-05-29 04:19:38 +00:00
|
|
|
var msgsShown = E.clip(this.msgs.length, 0, settings.maxMessages);
|
2022-04-06 23:30:39 +00:00
|
|
|
g.reset().clearRect(this.x, this.y, this.x+this.width, this.y+23);
|
2022-05-24 12:24:38 +00:00
|
|
|
for(let i = 0;i < msgsShown;i++) {
|
2022-05-29 04:19:38 +00:00
|
|
|
const msg = this.msgs[i];
|
2022-05-24 12:24:38 +00:00
|
|
|
const colors = [g.theme.bg, g.setColor(require("messages").getMessageImageCol(msg)).getColor()];
|
|
|
|
if (settings.flash && (c&1)) {
|
2022-06-08 04:36:36 +00:00
|
|
|
if (colors[1] == g.theme.fg) {
|
|
|
|
colors.reverse();
|
|
|
|
} else {
|
|
|
|
colors[1] = g.theme.fg;
|
|
|
|
}
|
2022-05-24 12:24:38 +00:00
|
|
|
}
|
|
|
|
g.setColor(colors[1]).setBgColor(colors[0]);
|
2022-07-25 14:53:59 +00:00
|
|
|
// draw the icon, or '...' if too many messages
|
|
|
|
g.drawImage(i == (settings.maxMessages - 1) && this.msgs.length > settings.maxMessages ? atob("EASBAGGG88/zz2GG") : require("messages").getMessageImage(msg),
|
|
|
|
this.x + 12 + i * 24, this.y + 12, {rotate:0/*force centering*/});
|
2022-05-24 12:24:38 +00:00
|
|
|
}
|
2022-04-06 23:30:39 +00:00
|
|
|
}
|
2022-07-15 11:10:52 +00:00
|
|
|
if (c<settings.vibrateTimeout && // not going on too long...
|
|
|
|
(settings.repeat || c<1) && // repeated, or no repeat and first attempt
|
|
|
|
(Date.now()-this.l)>settings.repeat*1000) { // the period between vibrations
|
2022-02-18 20:57:09 +00:00
|
|
|
this.l = Date.now();
|
2022-02-19 07:09:28 +00:00
|
|
|
WIDGETS["messages"].buzz(); // buzz every 4 seconds
|
2021-10-22 10:47:23 +00:00
|
|
|
}
|
2022-04-06 23:30:39 +00:00
|
|
|
WIDGETS["messages"].i=setTimeout(()=>WIDGETS["messages"].draw(true), 1000);
|
2021-12-09 19:54:39 +00:00
|
|
|
if (process.env.HWVERSION>1) Bangle.on('touch', this.touch);
|
2022-05-29 04:19:38 +00:00
|
|
|
},update:function(rawMsgs, quiet) {
|
2022-07-15 11:10:52 +00:00
|
|
|
const settings = Object.assign({maxMessages:3},require('Storage').readJSON("messages.settings.json", true) || {});
|
|
|
|
this.msgs = filterMessages(rawMsgs);
|
|
|
|
if (this.msgs.length === 0) {
|
|
|
|
delete this.t;
|
|
|
|
delete this.l;
|
2022-05-24 12:24:38 +00:00
|
|
|
} else {
|
2022-07-15 11:10:52 +00:00
|
|
|
this.t=Date.now(); // first time
|
|
|
|
this.l=Date.now()-10000; // last buzz
|
|
|
|
if (quiet) this.t -= 500000; // if quiet, set last time in the past so there is no buzzing
|
2022-05-24 12:24:38 +00:00
|
|
|
}
|
2022-07-25 14:53:59 +00:00
|
|
|
this.width = 24 * E.clip(this.msgs.length, 0, settings.maxMessages);
|
2021-11-23 16:28:34 +00:00
|
|
|
Bangle.drawWidgets();
|
2022-09-07 09:15:39 +00:00
|
|
|
},buzz:function(msgSrc) { // return a promise
|
2022-09-07 09:16:20 +00:00
|
|
|
if ((require('Storage').readJSON('setting.json',1)||{}).quiet) return Promise.resolve(); // never buzz during Quiet Mode
|
2022-07-06 05:49:16 +00:00
|
|
|
var pattern;
|
2022-06-28 10:43:25 +00:00
|
|
|
if (msgSrc != undefined && msgSrc.toLowerCase() == "phone") {
|
|
|
|
// special vibration pattern for incoming calls
|
2022-07-06 05:49:16 +00:00
|
|
|
pattern = (require('Storage').readJSON("messages.settings.json", true) || {}).vibrateCalls;
|
2022-06-28 10:43:25 +00:00
|
|
|
} else {
|
2022-07-06 05:49:16 +00:00
|
|
|
pattern = (require('Storage').readJSON("messages.settings.json", true) || {}).vibrate;
|
2022-06-28 10:43:25 +00:00
|
|
|
}
|
2022-07-06 05:49:16 +00:00
|
|
|
if (pattern === undefined) { pattern = ":"; } // pattern may be "", so we can't use || ":" here
|
2022-09-07 09:15:39 +00:00
|
|
|
return require("buzz").pattern(pattern);
|
2021-12-09 19:54:39 +00:00
|
|
|
},touch:function(b,c) {
|
|
|
|
var w=WIDGETS["messages"];
|
2022-07-25 14:53:59 +00:00
|
|
|
if (!w||!w.width||c.x<w.x||c.x>w.x+w.width||c.y<w.y||c.y>w.y+24) return;
|
2021-12-09 19:54:39 +00:00
|
|
|
load("messages.app.js");
|
2021-10-22 10:47:23 +00:00
|
|
|
}};
|
2022-05-24 12:24:38 +00:00
|
|
|
|
2021-12-06 14:27:11 +00:00
|
|
|
/* We might have returned here if we were in the Messages app for a
|
|
|
|
message but then the watch was never viewed. In that case we don't
|
|
|
|
want to buzz but should still show that there are unread messages. */
|
2022-05-29 04:19:38 +00:00
|
|
|
if (global.MESSAGES===undefined)
|
2022-08-09 13:48:04 +00:00
|
|
|
WIDGETS["messages"].update(require("messages").getMessages(), true);
|
2022-02-24 14:03:13 +00:00
|
|
|
})();
|