Problems responding to GB messages in a widget

Posted on
  • Hi,
    I am trying to write a widget that shows the currently played track.
    I have the following code:

    //WIDGETS = {};
    
    (() => {
      var musicInfo;
      
      var _GB = global.GB;
      global.GB = (event) => {
        switch (event.t) {
          case "musicinfo":
            musicInfo = event;
            WIDGETS["mymusic"].draw();
            break;
        }
        if(_GB)setTimeout(_GB,0,event);
      };
      
      function draw() {
        g.reset();
        g.clearRect(this.x,this.y,this.x+176,thi­s.y+16);
        g.setFont("Vector",16);
        
        if (musicInfo !== undefined) {
          g.drawString(musicInfo.track,this.x,this­.y);
        }
      }
      
      WIDGETS["mymusic"]={area:"bl",width:176,­draw:draw};
    })();
    
    //Bangle.drawWidgets();
    

    When loading into RAM it works. When using the left side of Espruino Web IDE and sending GB messages, the tracks are displayed.
    However, when loading the code in storage, it does not work. No tracks are displayed.
    What is the difference between RAM and storage?

  • Is your widget being displayed, but it's still not working?

    Maybe check with print(GB) which function is actually the one getting called.

  • Thank you for your feedback.
    The widget is displayed, only the GB events seem not to arrive.
    As an app the code works as well (without the widget-specific code, of course).
    Generally, the code (especially GB) should work as a widget?

    When running in RAM print(GB) (in the left side of the IDE) displayed the correct method (from the code above).
    When running in storage another method is displayed.
    I have no idea why this is happening.

  • I have now figured it out.
    The method called was from Gadgetbridge Music Controls. After uninstalling Gadgetbridge Music Controls it works now.
    This means that you can only bind the events once?
    Or is there a way that both can work?

    Thank you very much for the help. It is really fun to play around with the watch.

  • You can definitely bind to the event in more places: if (_GB) setTimeout(_GB,0,event); passes on the message after you handle it.
    But Gadgetbridge Music Controls deliberately doesn't pass on music events (to prevent the messages app from loading)

  • But Gadgetbridge Music Controls deliberately doesn't pass on music events (to prevent the messages app from loading)

    Ahh, well that'd make sense :) What you could do is call your code in a timeout, maybe 100ms after booting - so you try and get it in on top of Gadgetbridge music controls...

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

Problems responding to GB messages in a widget

Posted by Avatar for ingo @ingo

Actions