Skip to content

Commit

Permalink
messages: split library/gui/widget into separate apps
Browse files Browse the repository at this point in the history
  • Loading branch information
rigrig committed Nov 26, 2022
1 parent a9b12f0 commit 2a506e7
Show file tree
Hide file tree
Showing 41 changed files with 641 additions and 368 deletions.
1 change: 1 addition & 0 deletions apps/android/ChangeLog
Expand Up @@ -15,3 +15,4 @@
0.15: Allow method/body/headers to be specified for `http` (needs Gadgetbridge 0.68.0b or later)
0.16: Bangle.http now fails immediately if there is no Bluetooth connection (fix #2152)
0.17: Now kick off Calendar sync as soon as connected to Gadgetbridge
0.18: Use new message library
4 changes: 2 additions & 2 deletions apps/android/metadata.json
Expand Up @@ -2,11 +2,11 @@
"id": "android",
"name": "Android Integration",
"shortName": "Android",
"version": "0.17",
"version": "0.18",
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
"icon": "app.png",
"tags": "tool,system,messages,notifications,gadgetbridge",
"dependencies": {"messages":"app"},
"dependencies": {"messages":"module"},
"supports": ["BANGLEJS","BANGLEJS2"],
"readme": "README.md",
"storage": [
Expand Down
2 changes: 1 addition & 1 deletion apps/android/settings.js
Expand Up @@ -23,7 +23,7 @@
updateSettings();
}
},
/*LANG*/"Messages" : ()=>load("messages.app.js"),
/*LANG*/"Messages" : ()=>require("message").openGUI(),
};
E.showMenu(mainmenu);
})
3 changes: 2 additions & 1 deletion apps/hcclock/ChangeLog
@@ -1,4 +1,5 @@
0.01: Base code
0.02: Saved settings when switching color scheme
0.03: Added Button 3 opening messages (if app is installed)
0.04: Use `messages` library to check for new messages
0.04: Use `messages` library to check for new messages
0.05: Use `messages` library to open message GUI
2 changes: 1 addition & 1 deletion apps/hcclock/hcclock.app.js
Expand Up @@ -234,7 +234,7 @@ function handleMessages()
{
if(!hasMessages()) return;
E.showMessage("Loading Messages...");
load("messages.app.js");
require("messages").openGUI();
}

function hasMessages()
Expand Down
2 changes: 1 addition & 1 deletion apps/hcclock/metadata.json
@@ -1,7 +1,7 @@
{
"id": "hcclock",
"name": "Hi-Contrast Clock",
"version": "0.04",
"version": "0.05",
"description": "Hi-Contrast Clock : A simple yet very bold clock that aims to be readable in high luninosity environments. Uses big 10x5 pixel digits. Use BTN 1 to switch background and foreground colors.",
"icon": "hcclock-icon.png",
"type": "clock",
Expand Down
1 change: 1 addition & 0 deletions apps/ios/ChangeLog
Expand Up @@ -9,3 +9,4 @@
0.09: Enable 'ams' on new firmwares (ams/ancs can now be enabled individually) (fix #1365)
0.10: Added more bundleIds
0.11: Added letters with caron to unicodeRemap, to properly display messages in Czech language
0.12: Use new message library
2 changes: 1 addition & 1 deletion apps/ios/app.js
@@ -1,2 +1,2 @@
// Config app not implemented yet
setTimeout(()=>load("messages.app.js"),10);
setTimeout(()=>require("messages").openGUI(),10);
4 changes: 2 additions & 2 deletions apps/ios/metadata.json
@@ -1,11 +1,11 @@
{
"id": "ios",
"name": "iOS Integration",
"version": "0.11",
"version": "0.12",
"description": "Display notifications/music/etc from iOS devices",
"icon": "app.png",
"tags": "tool,system,ios,apple,messages,notifications",
"dependencies": {"messages":"app"},
"dependencies": {"messages":"module"},
"supports": ["BANGLEJS","BANGLEJS2"],
"readme": "README.md",
"storage": [
Expand Down
79 changes: 79 additions & 0 deletions apps/messagegui/ChangeLog
@@ -0,0 +1,79 @@
0.01: New App!
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)
0.06: New messages now go at the start (fix #898)
Answering true/false now exits the messages app if no new messages
Back now marks a message as read
Clicking top-left opens a menu which allows you to delete a message or mark unread
0.07: Added settings menu with option to choose vibrate pattern and frequency (fix #909)
0.08: Fix rendering of long messages (fix #969)
buzz on new message (fix #999)
0.09: Message now disappears after 60s if no action taken and clock loads (fix 922)
Fix phone icon (#1014)
0.10: Respect the 'new' attribute if it was set from iOS integrations
0.11: Open app when touching the widget (Bangle.js 2 only)
0.12: Extra app-specific notification icons
New animated notification icon (instead of large blinking 'MESSAGES')
Added screenshots
0.13: Add /*LANG*/ comments for internationalisation
Add 'Delete All' option to message options
Now update correctly when 'require("messages").clearAll()' is called
0.14: Hide widget when all unread notifications are dismissed from phone
0.15: Don't buzz when Quiet Mode is active
0.16: Fix text wrapping so it fits the screen even if title is big (fix #1147)
0.17: Fix: Get dynamic dimensions of notify icon, fixed notification font
0.18: Use app-specific icon colors
Spread message action buttons out
Back button now goes back to list of messages
If showMessage called with no message (eg all messages deleted) now return to the clock (fix #1267)
0.19: Use a larger font for message text if it'll fit
0.20: Allow tapping on the body to show a scrollable view of the message and title in a bigger font (fix #1405, #1031)
0.21: Improve list readability on dark theme
0.22: Add Home Assistant icon
Allow repeat to be switched Off, so there is no buzzing repetition.
Also gave the widget a pixel more room to the right
0.23: Change message colors to match current theme instead of using green
Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured
0.24: Remove left-over debug statement
0.25: Fix widget memory usage issues if message received and watch repeatedly calls Bangle.drawWidgets (fix #1550)
0.26: Setting to auto-open music
0.27: Add 'mark all read' option to popup menu (fix #1624)
0.28: Option to auto-unlock the watch when a new message arrives
0.29: Fix message list overwrites on Bangle.js 1 (fix #1642)
0.30: Add new Icons (Youtube, Twitch, MS TODO, Teams, Snapchat, Signal, Post & DHL, Nina, Lieferando, Kalender, Discord, Corona Warn, Bibel)
0.31: Option to disable icon flashing
0.32: Added an option to allow quiet mode to override message auto-open
0.33: Timeout from the message list screen if the message being displayed is removed and there is a timer going
0.34: Don't buzz for 'map' update messages
0.35: Reset graphics colors before rendering a message (possibly fix #1752)
0.36: Ensure a new message plus an almost immediate deletion of that message doesn't load the messages app (fix #1362)
0.37: Now use the setUI 'back' icon in the top left rather than specific buttons/menu items
0.38: Add telegram foss handling
0.39: Set default color for message icons according to theme
0.40: Use default Bangle formatter for booleans
0.41: Add notification icons in the widget
0.42: Fix messages ignoring "Vibrate: Off" setting
0.43: Add new Icons (Airbnb, warnwetter)
0.44: Separate buzz pattern for incoming calls
0.45: Added new app colors and icons
0.46: Add 'Vibrate Timer' option to set how long to vibrate for, and fix Repeat:off
Fix message removal from widget bar (previously caused exception as .hide has been removed)
0.47: Add new Icons (Nextbike, Mattermost, etc.)
0.48: When getting new message from the clock, only buzz once the messages app is loaded
0.49: Change messages icon (to fit within 24px) and ensure widget renders icons centrally
0.50: Add `getMessages` and `status` functions to library
Option to disable auto-open of messages
Option to make message icons monochrome (not colored)
messages widget buzz now returns a promise
0.51: Emit "message events"
Setting to hide widget
Add custom event handlers to prevent default app form loading
Move WIDGETS.messages.buzz() to require("messages").buzz()
0.52: Fix require("messages").buzz() regression
Fix background color in messages list after one unread message is shown
0.53: Messages now uses Bangle.load() to load messages app faster (if possible)
0.54: Move icons out to messageicons module
0.55: Rename to messagegui, move global message handling library to message module
Move widget to widmessage
68 changes: 68 additions & 0 deletions apps/messagegui/README.md
@@ -0,0 +1,68 @@
# Messages app

Default app to handle the display of messages and message notifications. It allows
them to be listed, viewed, and responded to.
It is installed automatically if you install `Android Integration` or `iOS Integration`.

It is a replacement for the old `notify`/`gadgetbridge` apps.


## Settings

You can change settings by going to the global `Settings` app, then `App Settings`
and `Messages`:

* `Vibrate` - This is the pattern of buzzes that should be made when a new message is received
* `Vibrate for calls` - This is the pattern of buzzes that should be made when an incoming call is received
* `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds
* `Vibrate Timer` - When a new message is received when in a non-clock app, we display the message icon and
buzz every `Repeat` seconds. This is how long we continue to do that.
* `Unread Timer` - When a new message is received when showing the clock we go into the Messages app.
If there is no user input for this amount of time then the app will exit and return
to the clock where a ringing bell will be shown in the Widget bar.
* `Min Font` - The minimum font size used when displaying messages on the screen. A bigger font
is chosen if there isn't much message text, but this specifies the smallest the font should get before
it starts getting clipped.
* `Auto-Open Music` - Should the app automatically open when the phone starts playing music?
* `Unlock Watch` - Should the app unlock the watch when a new message arrives, so you can touch the buttons at the bottom of the app?

## New Messages

When a new message is received:

* If you're in an app, the Bangle will buzz and a message icon appears in the Widget bar. You can tap this icon to view the message.
* If you're in a clock, the Messages app will automatically start and show the message

When a message is shown, you'll see a screen showing the message title and text.

* The 'back-arrow' button (or physical button on Bangle.js 2) goes back to Messages, marking the current message as read.
* The top-left icon shows more options, for instance deleting the message of marking unread
* On Bangle.js 2 you can tap on the message body to view a scrollable version of the title and text (or can use the top-left icon + `View Message`)
* If shown, the 'tick' button:
* **Android** opens the notification on the phone
* **iOS** responds positively to the notification (accept call/etc)
* If shown, the 'cross' button:
* **Android** dismisses the notification on the phone
* **iOS** responds negatively to the notification (dismiss call/etc)

## Images
_1. Screenshot of a notification_

![](screenshot.png)


## Requests

Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=messages%20app

## Creator

Gordon Williams

## Contributors

[Jeroen Peters](https://github.com/jeroenpeters1986)

## Attributions

Icons used in this app are from https://icons8.com
File renamed without changes.
@@ -1,5 +1,5 @@
/* Called when we have a new message when we're in the clock...
BUZZ_ON_NEW_MESSAGE is set so when messages.app.js loads it knows
BUZZ_ON_NEW_MESSAGE is set so when messagegui.app.js loads it knows
that it should buzz */
global.BUZZ_ON_NEW_MESSAGE = true;
eval(require("Storage").read("messages.app.js"));
eval(require("Storage").read("messagegui.app.js"));
25 changes: 19 additions & 6 deletions apps/messages/app.js → apps/messagegui/app.js
Expand Up @@ -19,7 +19,6 @@ require("messages").pushMessage({"t":"add","id":1,"src":"Maps","title":"0 yd - H
// call
require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bob","body":"12421312",positive:true,negative:true})
*/

var Layout = require("Layout");
var settings = require('Storage').readJSON("messages.settings.json", true) || {};
var fontSmall = "6x8";
Expand Down Expand Up @@ -49,8 +48,11 @@ to the clock. */
var unreadTimeout;
/// List of all our messages
var MESSAGES = require("messages").getMessages();
if (!Array.isArray(MESSAGES)) MESSAGES=[];
var onMessagesModified = function(msg) {

var onMessagesModified = function(type,msg) {
if (msg.handled) return;
msg.handled = true;
require("messages").apply(msg, MESSAGES);
// TODO: if new, show this new one
if (msg && msg.id!=="music" && msg.new && active!="map" &&
!((require('Storage').readJSON('setting.json', 1) || {}).quiet)) {
Expand All @@ -62,9 +64,15 @@ var onMessagesModified = function(msg) {
}
showMessage(msg&&msg.id);
};
Bangle.on("message", onMessagesModified);

function saveMessages() {
require("Storage").writeJSON("messages.json",MESSAGES)
require("messages").write(MESSAGES.map(m => {
delete m.show;
return m;
}));
}
E.on("kill", saveMessages);

function showMapMessage(msg) {
active = "map";
Expand Down Expand Up @@ -355,12 +363,16 @@ function checkMessages(options) {
}
// we have >0 messages
var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music");
var toShow = MESSAGES.find(m=>m.show);
if (toShow) {
newMessages.unshift(toShow);
}
// If we have a new message, show it
if (options.showMsgIfUnread && newMessages.length) {
if ((toShow||options.showMsgIfUnread) && newMessages.length) {
showMessage(newMessages[0].id);
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
if (global.BUZZ_ON_NEW_MESSAGE) {
// this is set if we entered the messages app by loading `messages.new.js`
// this is set if we entered the messages app by loading `messagegui.new.js`
// ... but only buzz the first time we view a new message
global.BUZZ_ON_NEW_MESSAGE = false;
// messages.buzz respects quiet mode - no need to check here
Expand Down Expand Up @@ -428,6 +440,7 @@ function cancelReloadTimeout() {
g.clear();

Bangle.loadWidgets();
require("messages").toggleWidget(false);
Bangle.drawWidgets();

setTimeout(() => {
Expand Down
Binary file added apps/messagegui/app.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/messagegui/boot.js
@@ -0,0 +1,3 @@
(function() {
Bangle.on("message", (type, msg) => require("messagegui").listener(type, msg));
})();
60 changes: 60 additions & 0 deletions apps/messagegui/lib.js
@@ -0,0 +1,60 @@
/**
* Listener set up in boot.js, calls into here to keep boot.js short
*/
exports.listener = function(type, msg) {
// Default handler: Launch the GUI for all unhandled messages (except music if disabled in settings)
if (msg.handled || (global.__FILE__ && __FILE__.startsWith('messagegui.'))) return; // already handled or app open

// if no new messages now, make sure we don't load the messages app
if (exports.messageTimeout && !msg.new && require("messages").status(msg) !== "new") {
clearTimeout(exports.messageTimeout);
delete exports.messageTimeout;
}
if (msg.t==="remove") return;

const appSettings = require("Storage").readJSON("messages.settings.json", 1) || {};
let loadMessages = (Bangle.CLOCK || event.important);
if (type==="music") {
if (Bangle.CLOCK && msg.new && appSettings.openMusic) loadMessages = true;
else return;
}
require("messages").save(msg);
msg.handled = true;
if (msg.t!=="add" || !msg.new) {
return;
}

const quiet = (require("Storage").readJSON("setting.json", 1) || {}).quiet;
const unlockWatch = appSettings.unlockWatch;
// don't auto-open messages in quiet mode if quietNoAutOpn is true
if ((quiet && appSettings.quietNoAutOpn) || appSettings.noAutOpn)
loadMessages = false;

// after a delay load the app, to ensure we have all the messages
if (exports.messageTimeout) clearTimeout(exports.messageTimeout);
exports.messageTimeout = setTimeout(function() {
delete exports.messageTimeout;
if (type!=="music") {
if (!loadMessages) return require("messages").buzz(msg.src); // no opening the app, just buzz
if (!quiet && unlockWatch) {
Bangle.setLocked(false);
Bangle.setLCDPower(1); // turn screen on
}
}
exports.open(msg);
}, 500);
};

/**
* Launch GUI app with given message
* @param {object} msg
*/
exports.open = function(msg) {
if (msg && msg.id && !msg.show) {
// store which message to load
msg.show = 1;
require("messages").save(msg, {force: 1});
}

Bangle.load((msg && msg.new && msg.id!=="music") ? "messagegui.new.js" : "messagegui.app.js");
};
22 changes: 22 additions & 0 deletions apps/messagegui/metadata.json
@@ -0,0 +1,22 @@
{
"id": "messagegui",
"name": "Messages",
"version": "0.55",
"description": "Default app to display notifications from iOS and Gadgetbridge/Android",
"icon": "app.png",
"type": "app",
"tags": "tool,system",
"supports": ["BANGLEJS","BANGLEJS2"],
"dependencies" : { "messageicons":"module" },
"provides_modules": ["messagegui"],
"readme": "README.md",
"storage": [
{"name":"messagegui","url":"lib.js"},
{"name":"messagegui.app.js","url":"app.js"},
{"name":"messagegui.new.js","url":"app-newmessage.js"},
{"name":"messagegui.boot.js","url":"boot.js"},
{"name":"messagegui.img","url":"app-icon.js","evaluate":true}
],
"screenshots": [{"url":"screenshot.png"}],
"sortorder": -9
}
File renamed without changes

0 comments on commit 2a506e7

Please sign in to comment.