Can I toggle widget display on/off?

Posted on
  • I'm working on a watch face that fills the whole screen including the widget area. I don't miss widgets because I find them too small to read at a glance, but I have added a second screen that briefly shows battery and step count (in a large font!) when I tap the watch face. I'm wondering if it's possible to include widgets just on that second screen.

    I've tried to do this by running Bangle.loadWidgets() and saving a copy of WIDGETS when the app is loaded, immediately before g.clear(). When the second screen is displayed I restore WIDGETS and run Bangle.drawWidgets(). After a timeout I set WIDGETS=[] before the original display is redrawn. This all works but I get an error message:

    Uncaught Error: Cannot read property 'width' of undefined
    at line 1 col 65 in widlock.wid.js
    WIDGETS["lock"].width=Bangle.isLocked()?­16:0;Bangle.drawWidg...
    in function called from system

    The restored copy of WIDGETS does contain ["lock"].width and anyway I get the same message if I run loadWidgets() again instead of restore plus drawWidgets(). The error doesn't seem to stop the watch running but I'd like to get rid of it. Is there a better way to toggle the widget display on/off?

    Thanks for any help.

  • There's nothing built-in, and it seems every clock that needs it implements their own hacks.

    ... but to try and avoid this, I just added a library. Developing with libraries requires a few tweaks: https://github.com/espruino/BangleApps/t­ree/master/modules

    but once that is done, you can just do require("widget_utils").hide() and require("widget_utils").show() now

  • Thanks for the quick reply - it sounds good but I can't get the module to work. Uploading the module to storage gave Uncaught ReferenceError: "exports" is not defined at line 4 col 8 in widget_utils followed by Module widget_utils not found when I ran it (and also when I changed the IDE search path ).

    But if I try require("wear_detect").isWorn().then(wor­n => {
    console.log(worn ? "is worn" : "not worn");
    });
    it works correctly.

    I must be missing something!

  • Did you read what was mentioned on https://github.com/espruino/BangleApps/t­ree/master/modules ? If you upload it to a file called widget_utils rather than widget_utils.js it might work?

    Adding the search path won't work right now as since I just added the module it's not uploaded to the main banglejs.com/apps site yet

  • I did read that and definitely loaded to widget_utils without the .js, just tried it again and got the same result. I also tried loading wear_detect into storage and got the same "exports not defined" error although it works fine when loaded from the site.

    Sorry to be making heavy weather of this...is there something else I need to do to get my watch to look for a local copy? Thanks.

  • ...but in the meantime I've just copied your code into my app and it works beautifully. Thanks again - I'm a new user of Bangle.js and I love it!

  • When i try to use the new widget_utils library i see the following in the Web IDE:

    Uncaught Error: Module widget_utils not found
     at line 100 col 43 in circlesclock.app.js
      let widgetUtils = require("widget_utils");
    
  • When i try to use the new widget_utils library i see the following in the Web IDE:

    Yes - that's expected because it's not on the main website yet. @myxor did you read https://github.com/espruino/BangleApps/b­lob/master/modules/README.md and upload the file to widget_utils in storage?

    I just tried this and it works great:

    • Use the IDE to upload widget_utils.js to a storage file called widget_utils
    • Call require("widget_utils").hide()
  • I am sorry, i didn't read the README in total. I now understand why this is expected.
    Thank you for clarification.

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

Can I toggle widget display on/off?

Posted by Avatar for BillV @BillV

Actions