Alternative to settings menu?

Posted on
  • I had some problem creating a settings menu for my clock. I wanted to preview different clock faces, for which i would need some functions from the clock app. Apparently, it is impossible to import functions into the settings app. My workaround was to just write a very basic settings.js:

    (function(back) {
      var settings = require('Storage').readJSON("contourcloc­k.json", true) || {};
      settings.editMode=true;
      require('Storage').writeJSON("contourclo­ck.json", settings);
      load('contourclock.app.js');
    })
    

    The clock app just has to check for "settings.editMode", disable UI and enter its own settings mode.
    Are there any problems with this approach?

  • One problem is you can't go back from the app settings to the settings menu.

    You could maybe put the drawing code in a separate library file, like e.g. the weather app does, so you'd have something like this:

    // apps/contourclock/lib.js
    exports.drawClock = function(time, face) {
      // draw clockface [#face](https://forum.espruino.com/searc­h/?q=%23face), at given time
    }
    
    // apps/contourclock/app.js
    var face = Storage.readJSON('contourclock.json').fa­ce
    setInterval(()=>require('contourclock').­drawClock(new Date(), face), 60000);
    
    // apps/contourclock/settings.js
    (function(back) {
    function preview(face) {
      require('contourclockclock').drawClock(n­ew Date(), face);
    }
    // settings menu using preview() goes here
    })
    
    // apps.json
    {
      "id": "contourclock"
    "storage": [
          {"name":"contourclock.app.js","url":"app­.js"},
          {"name":"contourclock","url":"lib.js"},
          {"name":"contourclock.settings.js","url"­:"settings.js"}
        ],
    }
    
  • Thanks a lot! One more problem: The drawClock function needs a font module. if i put

    require("FontTeletext10x18Ascii").add(Gr­aphics);
    

    in the main clock code, the font is loaded and works in drawClock. The same code does not work in the settings app, i get

    Contour Clock settings error: Error: Error: Module FontTeletext10x18Ascii not found
    Loading the font in the library does not work either, but does not produce an error message...

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

Alternative to settings menu?

Posted by Avatar for RaoulDuke @RaoulDuke

Actions