New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
messages: pass all messages through "message" event #2205
Conversation
apps/messages/widget.js
Outdated
@@ -51,5 +53,6 @@ WIDGETS["messages"]={area:"tl", width:0, draw:function(recall) { | |||
/* We might have returned here if we were in the Messages app for a | |||
message but then the watch was never viewed. */ | |||
if (global.MESSAGES===undefined) | |||
WIDGETS["messages"].update(require("messages").getMessages()); | |||
WIDGETS["messages"].onMsg('',{}); | |||
Bangle.on("message", WIDGETS["messages"].onMsg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If MESSAGES is defined and we're in the app, don't we still want to register our Bangle.on("message"
handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm not really sure what's going on here actually...
Do we even want to load the widget while in the messages app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question, maybe not... I just pushed a change to the messages lib that makes it 'fast load' the app if it can (which is really neat because it makes it much more responsive). But, that means that if the messages widget was already loaded, it'll stay loaded - so would have to cope with being around for the messages app anyway.
How are you feeling about this now? Did you have a chance to test it properly? Apart from that event handler registering I just posted, this looks good to me |
Whoops, I totally forgot, sorry. I'll have a look at it tonight. |
5c64341
to
4ceef51
Compare
Ran into a bug where |
Converted back to draft: this morning I didn't get any music notifications, so I'll have to look into that first :-( |
Thanks! This is looking good though |
Fixed it: there was a race when two events arrived in a row(e.g. |
Even to the default app/widget
Basically always keep MESSAGES in memory until event handlers have had a chance to run, so they don't all cause Storage.read()s when they call require("messages").getMessages()
Happens for music: we get both a musicinfo and a musicstate event, and when the first one finishes processing, it cleans up MESSAGES before the next event is done. Also just use exports.getMessages() to make sure it won't break.
5735335
to
e8bf4be
Compare
One thing I just thought about: it now saves all messages before emitting the event. |
Argh, yes - that's a pain. That could be problematic then. I thought the idea was that stuff like the music app could intercept the message before it got to be stored, so it didn't end up in the list of messages. What about updating the message list, and then instead of having it as a global MESSAGES we just pass it as an argument to the event (it might be better to make it a one-argument event that passes an object, so it's more readable/flexible?). Then we only write the message to storage if the message isn't handled, but things like the widget still get access to the full (new) list of messages? |
It was, but apparently I lost track of that somewhere.
I guess that makes sense, as we're loading
I could do that if you want, although I'm not really a fan of the idea. I think it makes sense for arguments with optional fields, but if we're always passing How about for now I'll adjust this PR so
And a follow-up PR to try and separate the "default" code from the library. |
It's just for readability really - but yes, let's keep it with args for now.
That sounds great. but...
You mean the messages app? Because at the moment the messages app needs to store them... |
Urgh, juggling too many message apps in my head. |
Closing in favour of #2297 |
Instead of directly calling from the lib into the app/widget, always use "message" events.
Also adds some optimization so we only read messages from storage once per event.
This also gets rid of the
update
method, see https://forum.espruino.com/comments/16740860/Marking this as draft because it's friday night, and I don't have time to properly test it, but other than that it is finished ;-)