Firefox SDK for easy storage and synchronization with Firefox

I am currently converting a Chrome extension in addition to Firefox and would like to replicate the chrome.storage.sync function.

However, I am unable to find whether the data stored by the Firefox add-in using simple-storage will automatically sync whenever the add-in user subscribes to Firefox Sync .

Given that all pieces of data stored by the latter method can be found in the user profile, I assume that he will be ... as long as the add-in is available at https://addons.mozilla.org ?

Any information on this topic would be greatly appreciated.

+4
source share
1 answer

simple-storagenot synchronized. But you can synchronize it with minimal effort.

Trick it into saving the object storage, it is serialized by definition as a string preference and tells the synchronization service to synchronize it.

Lets you name this preference syncstorageand mark it as synchronized.

var self = require("sdk/self");
var prefs = require("sdk/preferences/service");
prefs.set("services.sync.prefs.sync.extensions." + self.id + ".syncstorage", true);

When saving anything in, simple-storagereflect the change to syncstorage.

var sp = require("sdk/simple-prefs");
var ss = require("sdk/simple-storage");
sp.prefs["syncstorage"] = JSON.stringify(ss.storage);

For the opposite effect, see syncstoragefor changes.

sp.on("syncstorage", function(prefname){
  ss.storage = JSON.parse(sp.prefs["syncstorage"]);
})

And last, but not least, it would be good and, possibly, required for synchronization only with the explicit consent of the user.

+10
source

Source: https://habr.com/ru/post/1538236/


All Articles