Merge branch 'espruino:master' into master

master
Ronin0000 2021-11-23 12:22:27 -08:00 committed by GitHub
commit 6a93494e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 21 deletions

View File

@ -32,7 +32,7 @@
{
"id": "messages",
"name": "Messages",
"version": "0.04",
"version": "0.05",
"description": "App to display notifications from iOS and Gadgetbridge",
"icon": "app.png",
"type": "app",
@ -45,12 +45,13 @@
{"name":"messages.wid.js","url":"widget.js"},
{"name":"messages","url":"lib.js"}
],
"data": [{"name":"messages.json"}],
"sortorder": -9
},
{
"id": "android",
"name": "Android Integration",
"version": "0.02",
"version": "0.03",
"description": "(BETA) App to display notifications from Gadgetbridge on Android. This will eventually replace the Gadgetbridge widget.",
"icon": "app.png",
"tags": "tool,system,messages,notifications",
@ -66,7 +67,7 @@
{
"id": "ios",
"name": "iOS Integration",
"version": "0.02",
"version": "0.03",
"description": "(BETA) App to display notifications from iOS devices",
"icon": "app.png",
"tags": "tool,system,ios,apple,messages,notifications",

View File

@ -1,3 +1,4 @@
0.01: New App!
0.02: Remove messages on disconnect
Fix music control
0.03: Handling of message actions (ok/clear)

View File

@ -12,7 +12,7 @@
/* TODO: Call handling, fitness */
var HANDLERS = {
// {t:"notify",id:int, src,title,subject,body,sender,tel:string} add
"notify" : function() { event.t="add";require("messages").pushMessage(event); },
"notify" : function() { Object.assign(event,{t:"add",positive:true, negative:true});require("messages").pushMessage(event); },
// {t:"notify~",id:int, title:string} // modified
"notify~" : function() { event.t="modify";require("messages").pushMessage(event); },
// {t:"notify-",id:int} // remove
@ -36,8 +36,11 @@
},
// {"t":"call","cmd":"incoming/end","name":"Bob","number":"12421312"})
"call" : function() {
event.t=t.cmd=="incoming"?"add":"remove";
event.id="call";
Object.assign(event, {
t:event.cmd=="incoming"?"add":"remove",
id:"call", src:"Phone",
positive:true, negative:true,
title:event.name||"Call", body:"Incoming call\n"+event.number});
require("messages").pushMessage(event);
},
};
@ -58,5 +61,11 @@
Bangle.musicControl = cmd => {
// play/pause/next/previous/volumeup/volumedown
gbSend({ t: "music", n:cmd });
}
};
// Message response
Bangle.messageResponse = (msg,response) => {
if (msg.id=="call") return gbSend({ t: "call", n:response?"ACCEPT":"REJECT" });
if (isFinite(msg.id)) return gbSend({ t: "notify", n:response?"OPEN":"DISMISS" });
// error/warn here?
};
})();

View File

@ -1,2 +1,3 @@
0.01: New App!
0.02: Remove messages on disconnect
0.03: Handling of message actions (ok/clear)

View File

@ -96,7 +96,13 @@ Bangle.musicControl = cmd => {
// play, pause, playpause, next, prev, volup, voldown, repeat, shuffle, skipforward, skipback, like, dislike, bookmark
NRF.amsCommand(cmd);
};
NRF.on("disconnect", () => require("messages").clearAll()); // remove all messages on disconnect
// Message response
Bangle.messageResponse = (msg,response) => {
if (isFinite(msg.id)) return NRF.sendANCSAction(msg.id, response);//true/false
// error/warn here?
};
// remove all messages on disconnect
NRF.on("disconnect", () => require("messages").clearAll());
/*
// For testing...

View File

@ -2,3 +2,4 @@
0.02: Add 'messages' library
0.03: Fixes for Bangle.js 1
0.04: Add require("messages").clearAll()
0.05: Handling of message actions (ok/clear)

View File

@ -17,7 +17,7 @@
// maps
{"t":"add","id":1,"src":"Maps","title":"0 yd - High St","body":"Campton - 11:48 ETA","img":"GhqBAAAMAAAHgAAD8AAB/gAA/8AAf/gAP/8AH//gD/98B//Pg/4B8f8Afv+PP//n3/f5//j+f/wfn/4D5/8Aef+AD//AAf/gAD/wAAf4AAD8AAAeAAADAAA="}
// call
{"t:"add","id:"call","name":"Bob","number":"12421312"}
{"t":"add","id":"call","src":"Phone","name":"Bob","number":"12421312",positive:true,negative:true}
*/
var Layout = require("Layout");
@ -56,9 +56,16 @@ function saveMessages() {
function getBackImage() {
return atob("FhYBAAAAEAAAwAAHAAA//wH//wf//g///BwB+DAB4EAHwAAPAAA8AADwAAPAAB4AAHgAB+AH/wA/+AD/wAH8AA==");
}
function getPosImage() {
return atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA==");
}
function getNegImage() {
return atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA=");
}
function getMessageImage(msg) {
if (msg.img) return atob(msg.img);
var s = (msg.src||"").toLowerCase();
if (s=="Phone") return atob("FxeBABgAAPgAAfAAB/AAD+AAH+AAP8AAP4AAfgAA/AAA+AAA+AAA+AAB+AAB+AAB+OAB//AB//gB//gA//AA/8AAf4AAPAA=");
if (s=="skype") return atob("GhoBB8AAB//AA//+Af//wH//+D///w/8D+P8Afz/DD8/j4/H4fP5/A/+f4B/n/gP5//B+fj8fj4/H8+DB/PwA/x/A/8P///B///gP//4B//8AD/+AAA+AA==");
if (s=="hangouts") return atob("FBaBAAH4AH/gD/8B//g//8P//H5n58Y+fGPnxj5+d+fmfj//4//8H//B//gH/4A/8AA+AAHAABgAAAA=");
if (s=="whatsapp") return atob("GBiBAAB+AAP/wAf/4A//8B//+D///H9//n5//nw//vw///x///5///4///8e//+EP3/APn/wPn/+/j///H//+H//8H//4H//wMB+AA==");
@ -155,6 +162,28 @@ function showMessage(msgid) {
if (g.setFont(titleFont).stringWidth(title) > w)
title = g.wrapString(title, w).join("\n");
}
var buttons = [
{type:"btn", src:getBackImage(), cb:()=>checkMessages(true)}, // back
msg.new?{type:"btn", src:atob("HRiBAD///8D///wj///Fj//8bj//x3z//Hvx/8/fx/j+/x+Ad/B4AL8Rh+HxwH+PHwf+cf5/+x/n/PH/P8cf+cx5/84HwAB4fgAD5/AAD/8AAD/wAAD/AAAD8A=="), cb:()=>{
msg.new = false; // read mail
saveMessages();
checkMessages();
}}:{}
];
if (msg.positive) {
buttons.push({type:"btn", src:getPosImage(), cb:()=>{
msg.new = false; saveMessages();
Bangle.messageResponse(msg,true);
checkMessages();
}});
}
if (msg.negative) {
buttons.push({type:"btn", src:getNegImage(), cb:()=>{
msg.new = false; saveMessages();
Bangle.messageResponse(msg,true);
checkMessages();
}});
}
layout = new Layout({ type:"v", c: [
{type:"h", fillx:1, bgCol:colBg, c: [
{ type:"img", src:getMessageImage(msg), pad:2 },
@ -164,14 +193,7 @@ function showMessage(msgid) {
]},
]},
{type:"txt", font:fontMedium, label:msg.body||"", wrap:true, fillx:1, filly:1, pad:2 },
{type:"h",fillx:1, c: [
{type:"btn", src:getBackImage(), cb:()=>checkMessages(true)}, // back
msg.new?{type:"btn", src:atob("HRiBAD///8D///wj///Fj//8bj//x3z//Hvx/8/fx/j+/x+Ad/B4AL8Rh+HxwH+PHwf+cf5/+x/n/PH/P8cf+cx5/84HwAB4fgAD5/AAD/8AAD/wAAD/AAAD8A=="), cb:()=>{
msg.new = false; // read mail
saveMessages();
checkMessages();
}}:{}
]}
{type:"h",fillx:1, c: buttons}
]});
g.clearRect(Bangle.appRect);
layout.render();
@ -179,12 +201,15 @@ function showMessage(msgid) {
function checkMessages(forceShowMenu) {
// If no messages, just show 'no messages' and return
if (!MESSAGES.length)
return E.showPrompt("No Messages",{
if (!MESSAGES.length) {
if (forceShowMenu) return E.showPrompt("No Messages",{
title:"Messages",
img:require("heatshrink").decompress(atob("kkk4UBrkc/4AC/tEqtACQkBqtUDg0VqAIGgoZFDYQIIM1sD1QAD4AIBhnqA4WrmAIBhc6BAWs8AIBhXOBAWz0AIC2YIC5wID1gkB1c6BAYFBEQPqBAYXBEQOqBAnDAIQaEnkAngaEEAPDFgo+IKA5iIOhCGIAFb7RqAIGgtUBA0VqobFgNVA")),
buttons : {"Ok":1}
}).then(() => { load() });
load();
return;
}
// we have >0 messages
// If we have a new message, show it
if (!forceShowMenu) {
@ -195,7 +220,7 @@ function checkMessages(forceShowMenu) {
// Otherwise show a menu
E.showScroller({
h : 48,
c : MESSAGES.length+1,
c : Math.min(MESSAGES.length+1,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11)
draw : function(idx, r) {"ram"
var msg = MESSAGES[idx-1];
if (msg && msg.new) g.setBgColor(colBg);
@ -236,4 +261,4 @@ function checkMessages(forceShowMenu) {
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
checkMessages();
checkMessages(true); // force showing a menu