2.3 KiB
2.3 KiB
Messages library
This library handles the passing of messages. It can storess a list of messages and allows them to be retrieved by other apps.
Example
Assuming you are using GadgetBridge and "overlay notifications":
- Gadgetbridge sends an event to your watch for an incoming message
- The
androidapp parses the message, and callsrequire("messages").pushMessage({/** the message */}) require("messages")(provided bymessagelib) callsBangle.emit("message", "text", {/** the message */})- Overlay Notifications shows the message in an overlay, and marks it as
handled - The default GUI app (
messages) sees the event is marked ashandled, so does nothing. - The default widget (
widmessages) does nothing withhandled, and shows a notification icon. - You tap the notification, in order to open the full GUI Overlay Notifications
calls
require("messages").openGUI({/** the message */}) - The default GUI app (
messages) sees the "messageGUI" event, and launches itself
Events
When a new message arrives, a "message" event is emitted, you can listen for
it like this:
myMessageListener = Bangle.on("message", (type, message)=>{
if (message.handled) return; // another app already handled this message
// <type> is one of "text", "call", "alarm", "map", or "music"
// see `messagelib/lib.js` for possible <message> formats
// message.t could be "add", "modify" or "remove"
E.showMessage(`${message.title}\n${message.body}`, `${message.t} ${type} message`);
// You can prevent the default `message` app from loading by setting `message.handled = true`:
message.handled = true;
});
Apps can launch the full GUI by calling require("messages").openGUI(), if you
want to write your own GUI, it should include boot code that listens for
"messageGUI" events:
Bangle.on("messageGUI", message=>{
if (message.handled) return; // another app already opened it's GUI
message.handled = true; // prevent other apps form launching
Bangle.load("my_message_gui.app.js");
})
Requests
Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=messagelib%library
Creator
Gordon Williams
Contributors
Attributions
Icons used in this app are from https://icons8.com