Persistent local storage option for Client scripts


#1

This module enables Client scripts to store key/value strings using a subset of the localStorage Web API.

This is similar to using the built-in HiFi Settings API, but uses Qt WebEngineView to save values independently of Interface.ini.

In most scenarios the built-in Settings API should still be used – because most of the time being able to reset everything in one place is a good thing. Except when it’s not… in which case this solution could be used instead.

Please see the Gist’s README.MD for latest version and examples.

API overview:

To use via CDN:

Script.include('https://cdn.rawgit.com/humbletim/4efa277651f47698197da4bb324ef8db/raw/39fb4f13ad69a7bcc63cfecf2a19f3a72b0b577e/localStorage.js');

Example:

Script.include('localStorage.js');

var KEY = 'my-script-position';

localStorage.$ready(function() {
  localStorage.setItem(KEY, JSON.stringify(MyAvatar.position));
  var value = localStorage.getItem(KEY),
      pos = JSON.parse(value);
  print(KEY, value);
  localStorage.removeItem(KEY);
});

See localStorage.js for more info about where the data gets stored locally.