Data exchange between a widget and a clock face

Posted on
  • I'm working on a small project and I would like to know if there is an elegant way to exchange information between a widget and a clock face. I need to run part of my program in the background, so in a widget, but I would like to display information in the clock face.

    The reason is that certain processes should not be interrupted when the user presses the button to go to the setting screen.

    Is there a way to declare global variables between apps and widgets.

    thank you

  • All properties/functions of a widget are globally available as WIDGETS.widgetname.property, for example my widget has function setClockError which is available as WIDGETS.adjust.setClockError(x).

    The reason is that certain processes should not be interrupted when the user presses the button to go to the setting screen.

    All widgets are stopped and restarted when user goes to settings screen, just like when user changes to any other app. (Settings is just one of the apps.)

  • Some code for an example. If you define your widget as

    WIDGETS.mywidget = {
        area: ...,
        draw: ...,
        width: ...,
        someVariable: 123,
        someFunction: () => { ... },
      };
    

    Then in your clock, after calling Bangle.loadWidgets(), you can use WIDGETS.mywidget.someVariable and WIDGETS.mywidget.someFunction().

  • All widgets are stopped and restarted when user goes to settings
    screen, just like when user changes to any other app. (Settings is
    just one of the apps.)

    Ha! ok so my strategy is not the right one. Thanks for the quick response and relevant information.

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

Data exchange between a widget and a clock face

Posted by Avatar for user149221 @user149221

Actions