How to keep your setting even after restart/reset

Posted on
  • Have the use case to save app settings to be restore after startup/reset and decided to use .boot0.

    This is the snippet I started with:

    var defaults = { a:1, b:2, c:3 };
    var s = require('Storage');
    if (s.read('.boot0') === undefined) {
           s.write('.boot0',`var settings = ${JSON.stringify(defaults)}`);
           settings = defaults;
      }
    
    print(settings);
    
    // add  function to update `.boot0` if settings change ....
    

    How do you save your app settings?

  • Hi! i made a simple localStorage module to save my settings, maybe can help you
    This is a quick example on how to use it:

    var localStorage = require("localStorage").getInstance();

    var settingsObject = localStorage.getObject('settings');
    if (!settingsObject) {
    console.log("setting not exists");
    //here's how to set
    localStorage.setObject('settings', { 'ssid': 'blablabla', 'password': 'blablabla' });
    }
    else {
    console.log(settingsObject);
    //use the settings
    }


    1 Attachment

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

How to keep your setting even after restart/reset

Posted by Avatar for MaBe @MaBe

Actions