-
• #2
Personally, I'd just edit
messegesgui
and replaceshowMessage
with your code: https://github.com/espruino/BangleApps/blob/master/apps/messagegui/app.js#L248-L349But you can I believe just write code like:
Bangle.on("message", (type, msg) => { if (!msg) return; msg.handled = true; // don't do anything else with the message ... do stuff });
Maybe others that have actually done this can jump in though?
-
• #4
Thank you.
When I receive a message inBangle.on("message", (type, msg) => require("xxlmessage").listener(type, msg));
and I want to show a scrolling message, I need a timeout for the redraw, and a variable holding the current scroll position.
So I can make a global variable like:var scrollPosition=0; var scrollTimeout; exports.messageListener = function(type, msg) { }
Now, when I exit this code, by calling load(), will the global variables 'scrollPosition' etc. be freed from memory?
Also, can I break things, if my global variables have names that are used in other apps or the system?
I ask, because this code is in boot.js and thus always loaded. Will 'require()' load the js file on demand? What is the variable scope? The scope of require(), or global? -
• #5
by calling load(), will the global variables 'scrollPosition' etc. be freed from memory?
Yes -
load()
will remove everything from memory and start again. If you were usingBangle.load()
with fast load then you might have a problem, but withload()
it's fine.can I break things, if my global variables have names that are used in other apps or the system?
Yes, if they are truly global variables. You can always do:
{ let x = 123; //... }
let
will put variables in their own scope inside the curly braces.Will 'require()' load the js file on demand?
Yes
What is the variable scope? The scope of require(), or global?
If it's a module, the scope is in the module, not global.
-
• #6
Many thanks. Now I understand it.
What is the bare minimum code required to show a message from Gadgetbridge?
My eyes are too bad for reading the messages ui app. So I made a large font 2 line scroller that scrolls the message text two times and keeps the touch screen active. When you touch it, the clock loads.
Very simple. But, how would I get notified about a new message?