[Bangle2] Issue opening app settings with Button

Posted on
  • I'm having trouble opening Settings from another app. I saw some related topics and issues, but they don't apply exactly. This issue occurs on:

    • Emulator (v18.1) -> Setting visible; Stuck on "Loading..."
    • Device (v19.35) -> Settings visible; "Loading" -> Settings close immideately

    Here's some basic code to replicate this:

    var Layout = require("Layout");
    var layout = new Layout( {
      type:"txt", font:"6x8", label:"Test settings"
    });
    g.clear();
    layout.render();
    
    setWatch(
      function () {
        eval(require("Storage").read("myapp.sett­ings.js"))(()=>load());
      },
      BTN,
      { edge: "rising", debounce: 50, repeat: true }
    );
    

    and the settings app, copied from the examples:

    (function(back) {
      var FILE = "myapp.json";
      // Load settings
      var settings = Object.assign({
        something: 123,
      }, require('Storage').readJSON(FILE, true) || {});
    
      function writeSettings() {
        require('Storage').writeJSON(FILE, settings);
      }
    
      // Show the menu
      E.showMenu({
        "" : { "title" : "App Name" },
        "< Back" : () => back(),
        'On or off?': {
          value: !!settings.onoroff,  // !! converts undefined to false
          format: v => v?"On":"Off",
          onchange: v => {
            settings.onoroff = v;
            writeSettings();
          }
        },
        'How Many?': {
          value: 0|settings.howmany,  // 0| converts undefined to 0
          min: 0, max: 10,
          onchange: v => {
            settings.howmany = v;
            writeSettings();
          }
        },
      });
    })
    

    What's the problem? Am I missing something?
    I'm pretty sure this was working on v12.

    Edit:

    The "Loading..." appears pretty much as soon as I release the button.

    • On emulator, I can hold the button indefinitely and the menu remains

      // (1) PRESS BUTTON
      console.log('Open settings')
      eval(require("Storage").read("vhh.settin­gs.js"))(()=> {
      // (2) RELEASE BUTTON
      console.log('Close settings');
      load()
      })
      
    • On the device, of cource just ~2-3s.


    1 Attachment

    • screenshot (3).png
  • I wouldn't be too concerned about the emulator, but try setWatch( ..... {edge:"falling"})

    What's happening is you're responding on the rising edge but back responds on the falling edge, so it loads on press and then when you release it reloads.

  • Oh, wow. edge: "rising" was kinda staring me in the face; Didn't think to play with it.
    Thank you for the quick response!

    It also works fine in the emulator.

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

[Bangle2] Issue opening app settings with Button

Posted by Avatar for Franz @Franz

Actions