Minimum messages code?

Posted on
  • 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?

  • Personally, I'd just edit messegesgui and replace showMessage with your code: https://github.com/espruino/BangleApps/b­lob/master/apps/messagegui/app.js#L248-L­349

    But 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?

  • Yes, if you put that code in a boot file it should work, except you also want to check that

    1. type === 'text': only show notifications/sms
    2. msg.t !== 'remove': only show new/modified messages

    The messages library README has some example code using E.showMessage().

  • Thank you.
    When I receive a message in

    Bangle.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?

  • 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 using Bangle.load() with fast load then you might have a problem, but with load() 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.

  • Many thanks. Now I understand it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Minimum messages code?

Posted by Avatar for gfric @gfric

Actions