2022-11-20 14:41:02 +00:00
|
|
|
# Messages library
|
2021-10-22 10:47:23 +00:00
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
This library handles the passing of messages. It can storess a list of messages
|
|
|
|
and allows them to be retrieved by other apps.
|
2021-10-22 10:47:23 +00:00
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
## Example
|
2021-10-22 10:47:23 +00:00
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
Assuming you are using GadgetBridge and "overlay notifications":
|
2021-12-06 14:27:11 +00:00
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
1. Gadgetbridge sends an event to your watch for an incoming message
|
|
|
|
2. The `android` app parses the message, and calls `require("messages").pushMessage({/** the message */})`
|
|
|
|
3. `require("messages")` (provided by `messagelib`) calls `Bangle.emit("message", "text", {/** the message */})`
|
|
|
|
4. Overlay Notifications shows the message in an overlay, and marks it as `handled`
|
|
|
|
5. The default GUI app (`messages`) sees the event is marked as `handled`, so does nothing.
|
|
|
|
6. The default widget (`widmessages`) does nothing with `handled`, and shows a notification icon.
|
|
|
|
7. You tap the notification, in order to open the full GUI Overlay Notifications
|
|
|
|
calls `require("messages").openGUI({/** the message */})`
|
|
|
|
8. The default GUI app (`messages`) sees the "messageGUI" event, and launches itself
|
2021-12-06 14:27:11 +00:00
|
|
|
|
2021-10-22 10:47:23 +00:00
|
|
|
|
2022-02-03 14:00:48 +00:00
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
## Events
|
2022-09-24 12:48:59 +00:00
|
|
|
|
|
|
|
When a new message arrives, a `"message"` event is emitted, you can listen for
|
|
|
|
it like this:
|
|
|
|
|
|
|
|
```js
|
|
|
|
myMessageListener = Bangle.on("message", (type, message)=>{
|
2022-09-24 14:17:21 +00:00
|
|
|
if (message.handled) return; // another app already handled this message
|
2022-11-20 14:41:02 +00:00
|
|
|
// <type> is one of "text", "call", "alarm", "map", or "music"
|
|
|
|
// see `messagelib/lib.js` for possible <message> formats
|
2022-09-24 15:08:58 +00:00
|
|
|
// message.t could be "add", "modify" or "remove"
|
2022-09-24 12:48:59 +00:00
|
|
|
E.showMessage(`${message.title}\n${message.body}`, `${message.t} ${type} message`);
|
2022-09-24 14:17:21 +00:00
|
|
|
// You can prevent the default `message` app from loading by setting `message.handled = true`:
|
|
|
|
message.handled = true;
|
2022-09-24 12:48:59 +00:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
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:
|
|
|
|
|
|
|
|
```js
|
|
|
|
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");
|
|
|
|
})
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2021-10-22 10:47:23 +00:00
|
|
|
|
|
|
|
## Requests
|
|
|
|
|
2022-11-20 14:41:02 +00:00
|
|
|
Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=messagelib%library
|
2021-10-22 10:47:23 +00:00
|
|
|
|
|
|
|
## Creator
|
|
|
|
|
|
|
|
Gordon Williams
|
2021-12-14 00:34:30 +00:00
|
|
|
|
|
|
|
## Contributors
|
|
|
|
|
|
|
|
[Jeroen Peters](https://github.com/jeroenpeters1986)
|
|
|
|
|
|
|
|
## Attributions
|
|
|
|
|
|
|
|
Icons used in this app are from https://icons8.com
|