• I am tryin g to write a Theme Flipper Utility app that can be called from a gesture in the pattern launcher.

    The code just detects if the dark theme is loaded and flips to light and vice versa.
    The code should then just retart the default clock - but I'm not sure how to do that.

    With the code below, the settings switch correctly but I just end up with a blank screen.
    Its as if the app does not exit.

    const storage = require('Storage');
    let settings = storage.readJSON('setting.json', 1);
    
    function cl(x) { return g.setColor(x).getColor(); }
    
    function upd(th) {
      g.theme = th;
      settings.theme = th;
      storage.write('setting.json', settings);
      delete g.reset;
      g._reset = g.reset;
      g.reset = function(n) { return g._reset().setColor(th.fg).setBgColor(th­.bg); };
      g.clear = function(n) { if (n) g.reset(); return g.clearRect(0,0,g.getWidth(),g.getHeight­()); };
      g.clear(1);
    };
    
    function flipTheme() {
      if (!g.theme.dark) {
        upd({
          fg:cl("#fff"), bg:cl("#000"),
          fg2:cl("#0ff"), bg2:cl("#000"),
          fgH:cl("#fff"), bgH:cl("#00f"),
          dark:true
        });
      } else {
        upd({
          fg:cl("#000"), bg:cl("#fff"),
          fg2:cl("#000"), bg2:cl("#cff"),
          fgH:cl("#000"), bgH:cl("#0ff"),
          dark:false
        });
      }
    }
    
    Bangle.loadWidgets();
    Bangle.drawWidgets();
    
    flipTheme();
    load();
    
  • Just calling load() should do what you want - BUT the issue may be that load is being called before the initialisation of the current app is finished. Maybe try:

    setTimeout(load, 10);
    
  • Worked a treat, many thanks
    Brace yourself, new app being packaged tonight called 'flipper'.

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

How do I load the default clock on exit from an app that just changes settings

Posted by Avatar for HughB @HughB

Actions